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
Doss [256]
3 years ago
6

Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times

the character appears in the phrase. Ex: If the input is:
Computers and Technology
1 answer:
otez555 [7]3 years ago
4 0

Answer:

The program written in python is as follows

def countchr(phrase, char):

     count = 0

     for i in range(len(phrase)):

           if phrase[i] == char:

                 count = count + 1

     return count

phrase = input("Enter a Phrase: ")

char = input("Enter a character: ")

print("Occurence: ",countchr(phrase,char))

Explanation:

To answer this question, I made use of function

This line defines function countchr

def countchr(phrase, char):

This line initializes count to 0

     count = 0

This line iterates through each character of input phrase

     for i in range(len(phrase)):

This line checks if current character equals input character

           if phrase[i] == char:

The count variable is incremented, if the above condition is true

                 count = count + 1

The total number of occurrence is returned using this line

     return count

The main method starts here; This line prompts user for phrase

phrase = input("Enter a Phrase: ")

This line prompts user for a character

char = input("Enter a character: ")

This line prints the number of occurrence of the input charcater in the input phrase

print("Occurence: ",countchr(phrase,char))

You might be interested in
Mathematics and computer science share many concepts, such as recursion.
Virty [35]
The answer is B.

Read the answer I posted for your other question on the factorial of 7.
5 0
2 years ago
what is a tool or electrical system means intentionally creating a low-resistance path that connects to the earth
nikklg [1K]
A comper??><>?????????????????????????????????????
7 0
3 years ago
You've added a clip art image to your slide. Now you want to add a border. Which tab would you use to make this change?
Vinvika [58]
<span>If you want to add a border you have to use 'Insert' tab to make this change. Then you have to click on</span> "Picture" that is placed in the Insert menu, and choose "Clip Art." You can use the search box at the top of the Clip Art gallery in order to find a suitable border. When you finally found it, click on it, then select the button "Insert".
6 0
3 years ago
Read 2 more answers
Automatic red-eye reduction settings work best on which type of flash?
zhuklara [117]

Answer:

c

Explanation:

3 0
3 years ago
What is the domain and path in this URL? www.example.com/homepage.html​
Alex17521 [72]

Answer:

the domain is example.com. the path is /homepage

Explanation:

4 0
2 years ago
Other questions:
  • The prediction that the number of transistors on a chip would double about every two years is known as ________. Metcalfe's law
    6·1 answer
  • wHAT ARE THE 5 LAYERS in the internet protocol stack andwhat are the principal responsibilities of eack of theselayers.?
    12·1 answer
  • Write a program that has the following String variables: firstName, middleName, and lastName. Initialize these with your first,
    7·1 answer
  • PLEASE HELP FAST !!!!!!!!!!
    12·1 answer
  • Which one of the following statements is true regarding the fetch-execute cycle? Each step of the fetch-execute cycle is perform
    15·1 answer
  • If you define a destructor, are you required to define an operator '=' and a copy constructor?
    9·1 answer
  • Need the answer ASAP!!!!!!!!!!!!! I’ll mark brainliest if correct
    8·1 answer
  • Add me on Fortnite. Epic is smashman892. *Ik it sux but it's an old account* Comment ur epic
    6·2 answers
  • Your supervisor has asked you if it is possible to monitor servers for potential port scans via SNMP. What two OIDs can you prov
    13·1 answer
  • The Internet is based on a U.S. government project called ________. Today, the Internet is a collection of networks, tied togeth
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!