+ 2

Challenge help please!

The point to this code is to search some text for a word. My code below keeps printing "none" after it gives the correct output. I have no idea why it does this. Please Help! text = input() word = input() def search(t, w): """searches for a word within a string of words and reports whether or not the word is found in the text """ words = list(t.split(" ")) count = 0 for word in words: if w == words[count]: return print("Word found") else: count += 1 if count >= len(words): return print("Word not found") print(search(text, word))

3rd Apr 2021, 5:41 PM
Tabetha Ridgway
Tabetha Ridgway - avatar
2 Answers
+ 8
Tabetha Ridgway , the reason why it outputs "None" is that you return not only the output message, but also the print() statement. remove print() in all return expressions. happy coding;
3rd Apr 2021, 5:57 PM
Lothar
Lothar - avatar
3rd Apr 2021, 5:46 PM
Shadoff
Shadoff - avatar