0
The console returns "Word not found" even if the Word is in the Text. What's wrong with my Code, please reply!
4 Antworten
+ 3
ADHHAM CodeBoy
Always remember when you use if else condition inside loop then don't do return in both if and else part.
do like this
def search(txt, wrd):
for i in txt.split(" "):
if wrd == i:
return True
return False
text = input()
word = input()
if search (text, word):
print ('Word found')
else:
print ('Word not found')
+ 1
Hi, when you return something the operation ends. That's why if I put in text "good morning" and in word "morning" the first word won't be morning, the program will return "word not founded" and the operation ends. (Sorry for my english I'm trying my best x"D)
0
The Correct code isn't working as expected
0
Thank you AJ, your code worked and was so helpful to me