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 cylindrical specimen of a metal alloy 48.8 mm long and 9.09 mm in diameter is stressed in tension. A true stress of 327 MPa ca
Gnom [1K]

Answer:

The true stress necessary to plastically elongate the specimen is 406.69MPa

Explanation:

The Explanation or Solving is on the attached document.

5 0
3 years ago
Critical Thinking Scenario The Vice President for Compliance Management, Alexander Goodenuff, supports the position taken by Hen
Kisachek [45]

Answer:

True, True

Explanation:

1st Scenario: Purchase of new contamination equipment would indicate that the plant had been violating environmental regulations and reporting false data. So, Cathy and Henry must not purchase and install new contamination equipment unless the data indicates serious violatino of environmental regulations.

2nd Scenario: Company has the responsibiltiy to report contamination in plant water to regulatory agencies and Cathy Martin has been assigned this responsibility to report on behalf of the company. Reporting "adjusted" or inaccurate data is against the business ethics. So, professionally Cathy Martin is responsible for her reports to regulatory agencies.

8 0
4 years ago
(Architecture) Sarah is an environmental activist. She frequently conducts various programs and activities in her community to p
ddd [48]

The council from which Sarah can obtain her building certification is;

<u><em>US Green Building Council</em></u>

  • We are told that Sarah is an environmental activist because she conducts a lot of programs to advocate for clean and sustainable environment.

Now, there is a program called LEED which is an acronym for <em>Leadership in </em>

<em>Energy and Environmental Design</em> standards that is necessary for those

that want to measure the greenness of buildings.

     This <em>LEED</em> program explained above is organized by an organization in

the United States of America (USA) known as US Green Building Council

(USGBC). This program is for everyone who wants to be a certified

environmental activist and thus i t is recommended that Sarah gets her

certification here.

Read more at; brainly.com/question/24611198

5 0
3 years ago
When you see a street with white markings only, what kind of street is it?
Georgia [21]

Answer:

it's a one way street

3 0
4 years ago
I'm a grandma my Samuel needs to be tough in math what do I do
Sedbober [7]
Well you could always do what Hispanics do and repeat the question 2-3 times while yelling till they finally answer
7 0
3 years ago
Read 2 more answers
Other questions:
  • A bridge to be fabricated of steel girders is designed to be 500 m long and 12 m wide at ambient temperature (assumed 20°C). Exp
    9·1 answer
  • A cylindrical specimen of brass that has a diameter of 20 mm, a tensile modulus of 110 GPa, and a Poisson’s ratio of 0.35 is pul
    15·2 answers
  • Given x = 67 and y = 18, use two's complement to calculate:(1)x+y (2) x-y (3)-x+y (4)-x-y. Do the calculation, show the results
    7·1 answer
  • The entrance of the space module into atmosphere is one of the very critical phases of any space mission. Due to the formation o
    6·1 answer
  • A drilling operation is to be performed with a 12.7 mm diameter drill on cast iron. The hole depth is 60 mm and the drill point
    13·1 answer
  • What does the DHCP server configures for each host?
    14·1 answer
  • Advantage of a sheave wheel in a shaft headgear<br>​
    10·1 answer
  • In a black box experiment, when the amount of material exiting a closed system is less than the amount of material entering the
    7·1 answer
  • Please look at the picture for question.
    14·2 answers
  • What is the first step necessary for initiating the visual transduction cascade in rods?.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!