How to count the occurrence of a given character in a String?

How to count the occurrence of a given character in a String?

https://javarevisited.blogspot.com/2011/06/top-programming-interview-questions.html


CODE:

a = input('Enter a string: ')
b = input('Which char need to find occurence: ')
count = 0
for i in a:
    if b == i:
        count += 1
print(b,'character',count,'times occured in given string')

     

-----
By
PyKAR

Comments

Popular posts from this blog

Hardy - Ramanujan Number (Magic Number) Program in Python

FLAMES CODE ON PYTHON

Count Swap for Sorting in Python