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
Guys, can you rate this toolbox, please. It is my DT project, made for car trips, what do you think of the idea/design/usability
Maurinko [17]

Answer:

Honestly overall i think it looks fantastic

Explanation:

It looks like some really nice clean craftsmanship and i love the use of some different colors for some drawers to make it pop. the only con that i can possibly think of is that with it being wood and you moving it from place to place, some rubber feet or something that would prevent it from scratching/damaging anything else if it doesn't already (cant really see under it). other then that one thing i think it looks really good. well done.

3 0
3 years ago
____ grinders are used to grind diameters, shoulders, and faces much like the lathe is used for turning, facing, and boring oper
skelet666 [1.2K]

Answer:

Cylindrical

Explanation:

<em>A cylindrical grinder </em><em>is a tool for shaping the exterior of an item. Although cylindrical grinders may produce a wide range of forms, the item must have a central axis of rotation. Shapes such as cylinders, ellipses, cams, and crankshafts are examples of this.</em><em> Cylindrical grinding</em><em> machines are specialized grinding machines that are used to process cylinders, rods, and similar workpieces. The cylinders revolve in one direction between two centers, while the grinding wheel or wheels are close together and rotate in the other direction.</em>

8 0
2 years ago
Why was information revolution different or unique <br>​
Xelga [282]

Answer:

It made information easily accessible and ensured individuals became more vast in subject topics of interest.

Explanation:

Information revolution is different and unique and it came with the advent of computers and the internet. A lot of information is stored there which is too large and complex for the human brain.This helped people to access information without much stress as informations about almost every subject is on the Internet.

Individuals can check the informations up and become more vast in interested topics.

8 0
3 years ago
What might cause a shotgun to explode?
Tanzania [10]

Answer:

When you pull the trigger to shoot a shotshell from a shotgun or a cartridge from a rifle or handgun, the firing pin strikes the primer in the base of the cartridge or shotshell. This causes the primer to explode. The spark from the primer ignites the gunpowder, which burns rapidly and converts to a gas.

Explanation:

3 0
3 years ago
Read 2 more answers
A group of n Ghostbusters is battling n ghosts. Each Ghostbuster carries a proton pack, which shoots a stream at a ghost, eradic
babunello [35]

Answer:

Using the above algorithm matches one pair of Ghostbuster and Ghost. On  each side of the line formed by the pairing, the number of Ghostbusters and Ghosts are  the same, so use the algorithm recursively on each side of the line to find pairings. The  worst case is when, after each iteration, one side of the line contains no Ghostbusters  or Ghosts. Then, we need n/2 total iterations to find pairings, giving us an P(n^{2} lg n)-  time algorithm.

4 0
3 years ago
Other questions:
  • Consider the series solution, Equation 5.42, for the plane wall with convection. Calculate midplane (x* = 0) and surface (x* = 1
    5·1 answer
  • A rotating cup viscometer has an inner cylinder diameter of 2.00 in., and the gap between cups is 0.2 in. The inner cylinder len
    9·1 answer
  • For a 68 wt% Zn-32 wt% Cu alloy, make schematic sketches of the microstructure that would be observed for conditions of very slo
    14·1 answer
  • Consider laminar, fully developed flow in a channel of constant surface temperature Ts. For a given mass flow rate and channel l
    15·1 answer
  • How can the direction of rotation of a split-phase motor be changed? *
    15·2 answers
  • Water flows around a 6-ft diameter bridge pier with a velocity of 12 ft/s. Estimate the force (per unit length) that the water e
    8·1 answer
  • The diameter of a cylindrical water tank is Do and its height is H. The tank is filled with water, which is open to the atmosphe
    11·1 answer
  • If aligned and continuous carbon fibers with a diameter of 9.90 micron are embedded within an epoxy, such that the bond strength
    11·1 answer
  • What is required when setting up a smart phone as a WIFI hotspot?
    11·1 answer
  • Briefly explain the term soil sampling and outline its importance in building engineering works.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!