Python Program to input any sentence and sub-string print the index of given sub-string if found else print -1

 

mainstring=input('Enter any sentence : ')

tofind=input('Enter any word to find : ')

l1=len(tofind)

temp=False

for i in range(len(mainstring)-l1+1):

    twochar=mainstring[i:i+l1]

    if twochar==tofind:

       #print('Found at index : ',i)

       temp=True

    break

if temp==True:

    print('Found at index : ',i)

else:

    print('Not found at ',-1)





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