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
Based on the pattern, what are the next two terms of the sequence? 9,94,916,964,9256,... A. 91024,94096 B. 9260,91028 C. 9260,92
Hatshy [7]

Answer:

The answer is "Option A".

Explanation:

Series:

9, 94, 916, 964, 9256, ........

Solving the above series:

\to  9\\ \to  9(4) =94\\\to 9 (4^2) = 9(16) =916\\\to 9 (4^3) = 9(64) =964\\\to 9 (4^4) = 9(256) =9256\\\to 9 (4^5) = 9(1024) =91024\\\to 9 (4^6) = 9(4096) =94096\\

So, the series is:  9, 94, 916, 964, 9256, 91024, 94096, .................

6 0
3 years ago
How is an orthographic drawing similar to or different from an isometric drawing?
evablogger [386]
An isometrical drawing is a nearly 3d drawing showing the object's width and depth in a complete image, from each curved plane of the orthhographic view, the viewpoint is at a 45 degree angle. From an observations point of view, isometric differs, since all longitudes are true.
4 0
3 years ago
Read 2 more answers
Users of E85 see a drop in gas mileage because ethanol can't produce the same
liraira [26]

Answer:

A

Explanation:

Due to ethanol's lower energy content, FFVs operating on E85 get roughly 15% to 27% fewer miles per gallon than when operating on regular gasoline, depending on the ethanol content.

7 0
3 years ago
When do you know if you start volly ball
igomit [66]
Answer You ask your coach
7 0
3 years ago
A resistance of 30 ohms is placed in a circuit with a 90 volt battery. What current flows in the circuit?
blagie [28]

Answer:

3A

Explanation:

Using Ohms law U=I×R solve for I by I=U/R

4 0
3 years ago
Other questions:
  • A 55-μF capacitor has energy ω (t) = 10 cos2 377t J and consider a positive v(t). Determine the current through the capacitor.
    12·1 answer
  • A bar of 75 mm diameter is reduced to 73mm by a cutting tool while cutting orthogonally. If the mean length of the cut chip is 7
    10·1 answer
  • an adiabatic compressor receives 1.5 meter cube per second of air at 30 degrees celsius and 101 kpa. The discharge pressure is 5
    11·1 answer
  • Read a 4 character number. Output the result in in the following format, Input 9873, Output 3 *** 7 ******* 8 ******** 9 *******
    8·1 answer
  • Historically, the introduction of technology has caused profound changes in the labor market and, temporarily at least, displace
    6·1 answer
  • In an experiment, the local heat transfer over a flat plate were correlated in the form of local Nusselt number as expressed by
    5·1 answer
  • Write a program that asks the user for the name of a file. The program should display the number of words that the file contains
    7·1 answer
  • What is the difference between the pressure head at the end of a 150m long pipe of diameter 1m coming from the bottom of a reser
    7·1 answer
  • Select the correct answer. Which of the following devices is a simple machine? A.
    9·2 answers
  • which type of irrigation fluid is typically used for endoscopic procedures using monopolar electrosurgery
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!