Python Program to input any string and substring and search for substring and print the occurrence of substring in main string if it is there
# To understand find or search and index function
str = input ('Enter any sentence: ')
str=str.lower()
print (str)
ch = input ('Enter character to be found: ')
occ= int (input('Enter occurance of character to be found: ') )
c=str.count(ch)
if (occ>c):
print ('Not Found')
else:
for j in range (len(str)):
i=str[j]
if i==ch:
c-=1
if c==0:
print (occ,'occerance of ',ch,' is at position:',j)
break
Comments
Post a Comment