0

The console returns "Word not found" even if the Word is in the Text. What's wrong with my Code, please reply!

https://code.sololearn.com/cneHRnq68sIN/?ref=app

26th Feb 2021, 3:53 PM
ADHHAM CodeBoy
ADHHAM CodeBoy - avatar
4 odpowiedzi
+ 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')
26th Feb 2021, 4:35 PM
A͢J
A͢J - avatar
+ 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)
26th Feb 2021, 4:07 PM
WP_829
WP_829 - avatar
0
The Correct code isn't working as expected
26th Feb 2021, 4:10 PM
ADHHAM CodeBoy
ADHHAM CodeBoy - avatar
0
Thank you AJ, your code worked and was so helpful to me
27th Feb 2021, 1:58 AM
ADHHAM CodeBoy
ADHHAM CodeBoy - avatar