96.3k views
0 votes
Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday, the output is: 1 Ex: If the input is: z Today is Monday, the output is: 0 Ex: If the input is: n It's a sunny day, the output is: 2 Case matters. Ex: If the input is: n Nobody, the output is: 0 n is different than N.

User Tylerargo
by
3.9k points

1 Answer

7 votes

In python:

txt = input("What's your string? ")

n = input("What's your character? ")

print(txt.count(n))

I hope this helps!

User Eilene
by
4.2k points