Hey If you are beginner and want to learn a python then you are on right path. Learn basic as well as advanced programming in Python.

Search

Python program to count occurrence of Character in String.

PYHTON PROGRAM





str=input("Enter a String:")

ch=input("Enter a Character:")

flag=0

count=0

for i in range(len(str)):

if(str[i]==ch):

flag=1

count=count+1

if(flag==1):

print ("Character",ch,"is occured in String",count,"times")

else:

print ("Character",ch,"is not found")







*** Input && Output ***





No comments:

Post a Comment

let me know which type examples you want to comment me.