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

Some popular posts

Python Program that computes the net amount of a bank account based a transaction log from console input.

Python Program which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.The numbers obtained should be printed in a comma-separated sequence on a single line