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
During genetic engineering, how do Restriction enzymes know what base pairs to act on?
MaRussiya [10]

Answer:

The correct/closest option is b

Explanation:

Restriction enzymes are enzymes (endonucleases) that cut short DNA strands at specific sites. Hence, each restriction enzyme has it's own specific site (between two bases) it cuts at. There are two types of end that can be produced by this cut; the blunt end and the sticky end.

A restriction enzyme recognizes (palindromic sequence) and cut in it's own specific end.

For example, if a restriction enzyme cuts between a guanine (G) and an adenine (A), and it cuts a palindromic double stranded DNA in the manner below, it produces a sticky end.

G║AATTC

CTTAA║G

And if a restriction enzyme cuts between guanine (G) and cytosine (C) in the manner below, it produces a blunt end.

GGG║CCC

CCC║GGG

Hence, from the question, restriction enzymes (although chosen by the scientist based on desired sequence to be cut) recognize the sticky or blunt ends itself.

6 0
3 years ago
A coal-burning power plant generates electrical power at a rate of 650 megawatts (MW), or 6.50 × 108 J/s. The plant has an overa
Vinvika [58]

Answer:

Energy produce in one year =20.49 x 10¹⁶ J/year

Explanation:

Given that

Plant produce 6.50 × 10⁸ J/s of energy.

It produce  6.50 × 10⁸ J in 1 s.

We know that

1 year = 365 days

1 days = 24 hr

1 hr = 3600 s

1 year = 365 x 24 x 3600 s

1 year = 31536000 s

So energy produce in 1 year = 31536000 x  6.50 × 10⁸ J/year

          Energy produce in one year = 204984 x 10¹² J/year

          Energy produce in one year =20.49 x 10¹⁶ J/year

7 0
4 years ago
A budding electronics hobbyist wants to make a simple 1.0-nF capacitor for tuning her crystal radio, using two sheets of aluminu
bazaltina [42]

Answer:

a. 8 sheets of paper is needed between her plates to get the proper capacitance

b. Area of Aluminum Foil needed = 0.45m²

c. To keep a 1.0-nF, a larger area of Teflon is required.

Explanation:

a.

First, we need to calculate the distance between two plates.

This is given by

d = Kε0A/C

Where

K = 3

ε0 = Physical Constant = 8.854 * 10^-12 C²/Nm²

A = Area = 22 * 28 = 616cm² = 0.0616m²

C = 1.0-nF = 1 * 10^-12F

So, d = (3 * 8.854 * 10^-12 C²/Nm² * 0.0616) / (1 * 10^-12F)

d = 1.64 * 10^-3m

d = 1.64mm

Now, that the distance has been solved.

The Number of Sheets, N is given by

N = d/d,sheet where d, sheet =the sheet thickness = 0.2mm

N = 1.64/0.2

N = 8.2

N = 8 sheets --- Approximated

b.

Here, she's changed the diameter of the sheets to 12mm

Well make use of the formula in (a) above

Using d = Kε0A/C

Where

d = 12 * 10^-3m

Other constraints remain unchanged

Make A the subject of formula

A = dC/Kε0

A = (12 * 10^-3m * 1 * 10^-12F)/(3 * 8.854 * 10^-12 C²/Nm²)

A= 0.45m²

c. From (b) above

A ∝ 1/K

As the dielectric constant increase, the area decreases

The dielectric constant of a Teflon is 2.1

This means that if she used a Teflon instead, the area will be larger.

So, to keep a 1.0-nF, a larger area of Teflon is required.

7 0
4 years ago
LAB 3.3 – Working with String Input and Type CastingStep 1: RemovefindErrors.cppfrom the project and add thepercentage.cppprogra
jolli1 [7]

Answer:

// Program is written in C++ Programming Language

// Comments are used for explanatory purpose

#include<iostream>

using namespace std;

int main ()

{

// Variable declaration

string name;

int numQuestions;

int numCorrect;

double percentage;

//Prompt to enter student's first and last name

cout<<"Enter student's first and last name";

cin>>name; // this line accepts input for variable name

cout<<"Number of question on test"; //Prompt to enter number of questions on test

cin>> numQuestions; //This line accepts Input for Variable numQuestions

cout<<"Number of answers student got correct: "; // Prompt to enter number of correct answers

cin>>numCorrect; //Enter number of correct answers

percentage = numCorrect * 100 / numQuestions; // calculate percentage

cout<<name<<" "<<percentage<<"%"; // print

return 0;

}

Explanation:

The code above calculates the percentage of a student's score in a certain test.

The code is extracted from the Question and completed after extraction.

It's written in C++ programming language

4 0
4 years ago
What is the potiental energy of a 3 kg ball that is on the ground
Llana [10]

Answer:

147.15

Explanation:

147.15 is the answer

8 0
2 years ago
Other questions:
  • How I do I get nut out of sheets​
    8·2 answers
  • The creation of designer drugs is outpacing the ability of society to enact laws to prohibit them. Many of these substances have
    11·1 answer
  • The densities of several materials are given in SI units. Convert these to densities in U.S. customary units (slug/ft3), and als
    12·1 answer
  • Which of these is least likely a step in replacing a failed compressor?
    12·2 answers
  • Adore.aaliyah_ add me loves !
    7·1 answer
  • Identify the different engineering activities/steps in the engineering design process for each steps,summarize in 1–3 sentences
    13·1 answer
  • What energy type is represented in the picture?
    6·2 answers
  • Omg I just got 17/25 questions wrong using this on an Ag test , but got 100’s every time on health
    6·2 answers
  • To provide some perspective on the dimensions of atomic defects, consider a metal specimen that has a dislocation density of 105
    6·1 answer
  • 1. Làm thế nào để đảm bảo tính khả thi của văn bản hành chính ?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!