59.6k views
5 votes
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.

1 Answer

5 votes

Answer:

The program in Python is as follows:

print("Enter a character followed by a phrase",end='')

word = input(": ")

char = word[0]

print("Occurrence: "+str((word.count(char))-1))

Step-by-step explanation:

The prints an instruction to the user on how to input to the system

print("Enter a character followed by a phrase",end='')

This prompts and gets the user for input

word = input(": ")

This extracts the character from the input string

char = word[0]

This counts and prints the number of occurrence of the extracted character

print("Occurrence: "+str((word.count(char))-1))

User Mob
by
4.2k points