CBSE Class 11 Computer Science Question 77 of 91

String Manipulation — Question 1

Back to all questions
1
Question

Question 1

Write a program to count the number of times a character occurs in the given string.

Solution
str = input("Enter the string: ")
ch = input("Enter the character to count: ");
c = str.count(ch)
print(ch, "occurs", c, "times")
Output
Enter the string: KnowledgeBoat
Enter the character to count: e
e occurs 2 times
Answer