+ 1

Search engine project in python for beginners.

def search(sentence,word): for i in s: if (i==word): return True else: return False s=input() word=input() if (search(s,word)): print ("Word found") else: print ("Word not found") The code above always prints "word not found". Plz help.

28th May 2021, 10:05 AM
Simar Singh
Simar Singh - avatar
1 Antwort
+ 1
Simar Singh Don't use loop and compare value just do this if word in s: return True else: return False When you do " for i in s: " then it will compare "each character of given sentence with word" not "each word of given sentence with word".
28th May 2021, 11:04 AM
A͢J
A͢J - avatar