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
The Stefan-Boltzmann law can be employed to estimate the rate of radiation of energy H from a surface, as in
Mazyrski [523]

Explanation:

A.

H = Aeσ^4

Using the stefan Boltzmann law

When we differentiate

dH/dT = 4AeσT³

dH/dT = 4(0.15)(0.9)(5.67)(10^-8)(650)³

= 8.4085

Exact error = 8.4085x20

= 168.17

H(650) = 0.15(0.9)(5.67)(10^-8)(650)⁴

= 1366.376watts

B.

Verifying values

H(T+ΔT) = 0.15(0.9)(5.67)(10)^-8(670)⁴

= 1542.468

H(T+ΔT) = 0.15(0.9)(5.67)(10^-8)(630)⁴

= 1205.8104

Error = 1542.468-1205.8104/2

= 168.329

ΔT = 40

H(T+ΔT) = 0.15(0.9)(5.67)(10)^-8(690)⁴

= 1735.05

H(T-ΔT) = 0.15(0.9)(5.67)(10^-8)(610)⁴

= 1735.05-1059.83/2

= 675.22/2

= 337.61

5 0
3 years ago
Create two arrays with 5 elements each: one will hold Strings and the second will hold integers. Write a program to ask the user
MrMuchimi

Answer:

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

int main() {

   string name[5];  

   int age[5];  

   int i,j;  

   for ( i = 0; i<=4; i++ ) {  

       cout << "Please enter student's name:";  

       cin >> name[i];  

       cout << "Please enter student's age:";  

       cin >> age[i];          

   }  

for (i=0;i<=4;i++){

   cout<<"Age of  "<< name[i]<<"  is  "<<age[i]<<endl;  

}

}

Output of above program is displayed in figure attached.

5 0
3 years ago
How to update android 4.4.2 to 5.1​
faust18 [17]

Answer:

try settings and go to updates?

Explanation:

8 0
3 years ago
Much of the workd went to bed hungry
Marysya12 [62]
The workers went to bed hungry probably because they are hard workers and so didn’t want to eat because they didn’t want to take break┌(; ̄◇ ̄)┘
7 0
3 years ago
What is the difference between a refrigeration cycle and a heat pump cycle?
sukhopar [10]

Answer:

In refrigeration cycle heat transfer from inside refrigeration

In heat pump cycle heat transfer from environment

Explanation:

heat cycle is mechanical process use for cool the temperature but

In refrigeration heat transfer from inside of refrigeration that decrease temperature of refrigerator and in heat pump it decrease temperature negligible as compare to refrigerator

5 0
3 years ago
Other questions:
  • If a steel cable is rated to take 800-lb and the steel has a yield strength of 90,000psi, what is the diameter of the cable?
    12·1 answer
  • ¿Cuál era probablemente el activo más valioso de Persia?
    10·2 answers
  • A student is using a 12.9 ft ramp to raise an object 6 ft above the ground.
    5·1 answer
  • A heat engine that receives heat from a furnace at 1200°C and rejects waste heat to a river at 20°C has a thermal efficiency of
    14·1 answer
  • The attached program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number
    10·1 answer
  • Sam promises to pay Sandy $2,000 in four years and another $3,000 four years later for a loan of $2,000 from Sandy today. What i
    8·1 answer
  • 5 kg of a wet steam has a volume of 2 m3
    8·1 answer
  • Just need someone to talk to pls dont just use me for points
    5·1 answer
  • What do you think of web 3.0? do you think it will be realized someday in the future?​
    5·1 answer
  • A bakery wants to determine how many trays of doughnuts it should prepare each day. Demand is normal with a mean of 15 trays and
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!