1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Crank
3 years ago
10

Write a method called letterCount that takes two String arguments, one containing some text and the other containing a single le

tter. This method should then compute and return the count of all of the occurrences of that letter in the given text.

Engineering
1 answer:
jenyasd209 [6]3 years ago
4 0

Answer:

I am writing a Python program.  Here is the function letterCount. This function takes two string arguments text and letter and return count of all occurrences of a letter in the text.

def letterCount(text, letter):  

 count = 0  # to count occurrences of letter in the text string

 for char in text:  # loop moves through each character in the text

   if letter == char: # if given letter matches with the value in char

     count += 1  # keeps counting occurrence of a letter in text

 return count # returns how many times a letter occurred in text

   

Explanation:

In order to see if this function works you can check by calling this function and passing a text and a letter as following:

print(letterCount('apples are tasty','a'))

Output:

3

Now lets see how this function works using the above text and letter values.

text = apples are tasty

letter = a

So the function has to compute the occurrences of 'a' in the given text 'apples are tasty'.

The loop has a variable char that moves through each character given in the text (from a of apples to y of tasty) so it is used as an index variable.

char checks each character of the text string for the occurrence of letter a.

The if condition checks if the char is positioned at a character which matches the given letter i.e. a. If it is true e.g if char is at character a of apple so the if condition evaluates to true.

When the if condition evaluates to true this means one occurrence is found and this count variable counts this occurrence. So count increments every time the occurrence of letter a is found in apples are tasty text.

The loop breaks when every character in text is traversed and finally the count variable returns all of the occurrences of that letter (a) in the given text (apples are tasty). As a occurs 3 times in text so 3 is returned in output.

The screen shot of program along with output is attached.

You might be interested in
A fluid of specific gravity 0.96 flows steadily in a long, vertical 0.71-in.-diameter pipe with an average velocity of 0.90 ft/s
KengaRu [80]

Answer:

0.00650 Ib s /ft^2

Explanation:

diameter ( D ) = 0.71 inches = 0.0591 ft

velocity = 0.90 ft/s ( V )

fluid specific gravity = 0.96 (62.4 )  ( x )

change in pressure ( P ) = 0 because pressure was constant

viscosity =  (change in p - X sin∅ ) D^{2} / 32 V

              = ( 0 - 0.96( 62.4) sin -90 ) * 0.0591 ^2  / 32 * 0.90

              = - 59.904 sin (-90) * 0.0035 / 28.8

              = 0.1874 / 28.8

  viscosity = 0.00650 Ib s /ft^2

8 0
3 years ago
Read 2 more answers
In the planning process of the product development life cycle what is it important to inventory
Verizon [17]

Your Answer would be A I believe.

6 0
3 years ago
Unit for trigonometric functions is always "radian". 1. 10 points: Do NOT submit your MATLAB code for this problem (a) Given f(x
RoseWind [281]

Answer:

Below is the required code.

Explanation:

%% Newton Raphson Method

clear all;

clc;

x0=input('Initial guess:\n');

x=x0;

f=exp(-x)-sin(x)-0.2;

g=-exp(-x)-cos(x);

ep=10;

i=0;

cc=input('Condition of convergence:\n');

while ep>=cc

i=i+1;

temp=x;

x=x-(f/g);

f=exp(-x)-sin(x)-0.2;

g=-exp(-x)-cos(x);

ep=abs(x-temp);

fprintf('x = %6f and error = %6f at iteration = %2f \n',x,ep,i);

end

fprintf('The solution x = %6f \n',x);

%% End of MATLAB Program

Command Window:

(a) First Root:

Initial guess:

1.5

Condition of convergence:

0.01

x = -1.815662 and error = 3.315662 at iteration = 1.000000

x = -0.644115 and error = 1.171547 at iteration = 2.000000

x = 0.208270 and error = 0.852385 at iteration = 3.000000

x = 0.434602 and error = 0.226332 at iteration = 4.000000

x = 0.451631 and error = 0.017029 at iteration = 5.000000

x = 0.451732 and error = 0.000101 at iteration = 6.000000

The solution x = 0.451732

>>

Second Root:

Initial guess:

3.5

Condition of convergence:

0.01

x = 3.300299 and error = 0.199701 at iteration = 1.000000

x = 3.305650 and error = 0.005351 at iteration = 2.000000

The solution x = 3.305650

>>

(b) Guess x=0.5:

Initial guess:

0.5

Condition of convergence:

0.01

x = 0.450883 and error = 0.049117 at iteration = 1.000000

x = 0.451732 and error = 0.000849 at iteration = 2.000000

The solution x = 0.451732

>>

Guess x=1.75:

Initial guess:

1.75

Condition of convergence:

0.01

x = 227.641471 and error = 225.891471 at iteration = 1.000000

x = 218.000998 and error = 9.640473 at iteration = 2.000000

x = 215.771507 and error = 2.229491 at iteration = 3.000000

x = 217.692636 and error = 1.921130 at iteration = 4.000000

x = 216.703197 and error = 0.989439 at iteration = 5.000000

x = 216.970438 and error = 0.267241 at iteration = 6.000000

x = 216.971251 and error = 0.000813 at iteration = 7.000000

The solution x = 216.971251

>>

Guess x=3.0:

Initial guess:

3

Condition of convergence:

0.01

x = 3.309861 and error = 0.309861 at iteration = 1.000000

x = 3.305651 and error = 0.004210 at iteration = 2.000000

The solution x = 3.305651

>>

Guess x=4.7:

Initial guess:

4.7

Condition of convergence:

0.01

x = -1.916100 and error = 1.051861 at iteration = 240.000000

x = -0.748896 and error = 1.167204 at iteration = 241.000000

x = 0.162730 and error = 0.911626 at iteration = 242.000000

x = 0.428332 and error = 0.265602 at iteration = 243.000000

x = 0.451545 and error = 0.023212 at iteration = 244.000000

x = 0.451732 and error = 0.000187 at iteration = 245.000000

The solution x = 0.451732

>>

Explanation:

The two solutions are x =0.451732 and 3.305651 within the range 0 < x< 5.

The initial guess x = 1.75 fails to determine the solution as it's not in the range. So the solution turns to unstable with initial guess x = 1.75.

7 0
3 years ago
PLEASE HELP QUICK!!
ivolga24 [154]

R01= 14.1 Ω

R02=  0.03525Ω

<h3>Calculations and Parameters</h3>

Given:

K= E2/E1 = 120/2400

= 0.5

R1= 0.1 Ω, X1= 0.22Ω

R2= 0.035Ω, X2= 0.012Ω

The equivalence resistance as referred to both primary and secondary,

R01= R1 + R2

= R1 + R2/K2

= 0.1 + (0.035/9(0.05)^2)

= 14.1 Ω

R02= R2 + R1

=R2 + K^2.R1

= 0.035 + (0.05)^2 * 0.1

= 0.03525Ω

Read more about resistance here:

brainly.com/question/17563681

#SPJ1

5 0
2 years ago
Question 21(Multiple Choice
Katen [24]

Answer:

four seconds

Explanation:

lookin at a vehicle respectively at a second can cause accident

8 0
3 years ago
Read 2 more answers
Other questions:
  • How does the modern Diesel engine achieve higher power output without the use of higher compression ratio?
    5·1 answer
  • A 3-phase induction motor is being driven at a frequency of 80 Hz, and the motor speed is 1000 rpm. How many poles does the moto
    8·1 answer
  • (a) Consider a germanium semiconductor at T 300 K. Calculate the thermal equilibrium electron and hole concentrations for (i) Nd
    7·1 answer
  • 1. What are the usual symptoms of brake issues?​
    15·1 answer
  • Why is communication one of the most important aspects of an engineer’s job?
    7·2 answers
  • Calculate the tensile modulus of elasticity for a laminated composite consisting of 62 percent by volume of unidirectional carbo
    8·1 answer
  • Which of the following best describes the basic purpose of the internet?
    7·2 answers
  • Why is it important to follow the engineering design process before building a prototype
    13·1 answer
  • Which - type of service shop is least likely to provide service to all
    9·1 answer
  • An American architect whose principles of building included consonance with the landscape was ____________________________.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!