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
Lisa [10]
3 years ago
9

Write a function that finds the number of occurrences of a specified character in the string using the following header: def cou

nt(s, ch): For example, count("Welcome", 'e') returns 2. The str class has the count method. Implement your function without using the count method. Write a test program that reads a string and a character and displays the number of occurrences of the character in the string.
Computers and Technology
1 answer:
Ludmilka [50]3 years ago
6 0

Answer:

def count(userInput, character):

   occurrences = 0

   for character_in_string in userInput:

       if(character == character_in_string):

           occurrences += 1

   return occurrences

userInput = input("Enter string: ")

character = input("Enter character: ")[0]

print(count(userInput, character))

Explanation:

  • Define a count function that takes in the userInput as a string and character parameters.
  • Loop through the userInput and check whether selected character is equal to the character found in the string.
  • Increase the counter of occurrences by 1 if the condition is true and then return the occurrences.
  • Take the userInput and character as input from the user.
  • Finally display the results by calling the count function.
You might be interested in
The following is the correct way to write a for loop
Rzqust [24]

Answer:

for i in range

Explanation:

This is the only excerpt of code

3 0
3 years ago
A set of blocks contains blocks of heights 1,2, and 4 centimeters. Imagine constructing towers of piling blocks of different hei
SashulF [63]

Answer:

In studies about new medicines, researchers usually give one group of patients the medicine that is designed to treat an illness. They give another group of patients a placebo, which is taken the same way as the medicine but does not actually contain the ingredients of any medicine. Different medicines are tested in different experiments, but the placebos usually contain the same non-medical ingredients. If both groups of patients are healed, then researchers cannot be sure whether the medicine caused improvement, but if the group given the medicine is healed while the group given the placebo remains ill, researchers can conclude that the medicine causes the illness to go away.

In medical experiments, which group receives placebos?

the experimental group

the control group

both the experimental and control groups

neither the experimental nor control group

Explanation:

5 0
3 years ago
Por favor alguem poderia me falar qual PC e melhor: Computador Gamer Fox PC FPS Intel Core i5 8GB (GeForce GTX 1050Ti 4GB GDDR5)
Ivanshal [37]

Eu acredito no primeiro como ele tem uma GTX 1050ti, i5 e 2tb.

3 0
3 years ago
Your company needs to develop an Apex trigger in a sandbox to work with large amounts of records. The trigger needs to be tested
Svetllana [295]
C. Partial Copy Sandbox

5 0
3 years ago
From 1995 to 1997, the number of web users
BigorU [14]
Quadrupled. I think sorry if you get it wrong i do not remember much
7 0
3 years ago
Read 2 more answers
Other questions:
  • JAVA When simply determining the order of magnitude of an algorithm using Big-Oh algorithm analysis, an instruction that evaluat
    14·1 answer
  • Suppose company A wants to develop a program that duplicates the functionality of a programm by company B. Describe how company
    8·1 answer
  • Dr. Robbins wants to know if there are different opinions regarding the value of public school education between Native American
    11·1 answer
  • True or False?Only flying unmanned aircraft over 20lbs requires preparation and safety calculations.
    8·1 answer
  • Today you turned on your computer after being on vacation for a week. You see spinning white dots on a black screen. You decide
    11·1 answer
  • Directions Interview your parent or any member of your family. Identity
    12·1 answer
  • Will this website ever get itself together to stop people from sending links?
    9·1 answer
  • Trees 1. 2. 3. 4. 5.​
    6·1 answer
  • As we’ve discussed, computer programs are considered creative works and are protected by copyright. That means those programs be
    12·1 answer
  • Select the correct text in the passage.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!