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
Cat is stuck in 10 foot hole how do i get it unstuck
Semenov [28]

Answer:

you fill the hole so there is no more cat

7 0
2 years ago
Read 2 more answers
A wall that cannot be moved because it is carrying the weight of the roof is considered a wall
ad-work [718]

Answer:

Blank wall

Explanation:

A wall that cannot be moved because it is carrying the weight of the roof is considered a blank wall.

5 0
2 years ago
It's not a slot machine
scoundrel [369]
Maybe it’s a vending machine, I’m confused too
5 0
3 years ago
Read 2 more answers
Consider a refrigerator that consumes 320 W of electric power when it is running. If the refrigerator runs only one quarter of t
Semenov [28]

Answer:

B. $5.18

Explanation:

Cost of electricity per kWh = $0.09

Power consumption of refrigerator = 320W = 320/1000 = 0.32kW

In a month (30 days) the refrigerator works 1/4 × 30 days = 7.5 days = 7.5 × 24 hours = 180 hours

Energy consumed in 180 hours = 0.32kW × 180h = 57.6kWh

Cost of electricity of 57.6kWh energy consumed by the refrigerator = 57.6 × $0.09 = $5.18

3 0
3 years ago
Read 2 more answers
if two or more resistors are connected in parallel, the total resistance is _ than any single resistor
Andreas93 [3]
Parallel Resistor Equation
If the two resistances or impedances in parallel are equal and of the same value, then the total or equivalent resistance, RT is equal to half the value of one resistor. That is equal to R/2 and for three equal resistors in parallel, R/3, etc.
7 0
3 years ago
Other questions:
  • Compare automation and autonomous
    12·1 answer
  • Find the linear speed of the bottom of a test tube in a centrifuge if the centripetal acceleration there is 5.4×104 times the ac
    6·1 answer
  • There are a number of requirements that employers must do to protect their workers from caught-in or
    12·1 answer
  • A harmonic oscillator with spring constant, k, and mass, m, loses 3 quanta of energy, leading to the emission of a photon.
    13·1 answer
  • Define a function pyramid_volume with parameters base_length, base_width, and pyramid_height, that returns the volume of a pyram
    10·1 answer
  • Which of the following is a advantage of a chain and sprocket over a pulley and belt system?
    7·1 answer
  • When checking the resistance of a dual voltage wye motor, there should be ____ resistance readings. 1) twelve 2) six 3) three
    12·1 answer
  • Dear sir i want to ask something about the solution of my question?
    9·1 answer
  • Binary classification algorithm
    9·1 answer
  • with a digital system, if you have measured incorrectly and use too low of a kvp for adequate penetration, what do you need to d
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!