How to do the Search engine challenge in python?It prints”word found” and then it prints “none” in the next line. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to do the Search engine challenge in python?It prints”word found” and then it prints “none” in the next line.

text = input() word = input() def search(x,y): if word in text: print("Word found") else: print("Word not found") print(search(text, word))

30th May 2021, 8:56 AM
Joel Sebastian Jijo
Joel Sebastian Jijo - avatar
6 Answers
+ 2
text = input() word = input() def search(x,y): if word in text: print("Word found") else: print("Word not found") search(text, word)
30th May 2021, 9:03 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 3
Joel Sebastian Jijo If you have already printed value in function then no need to print that function because you may also get None because of no return statement. Note : If you don't return anything in function and you print that function then you may get None. So you just need to call function in this case. You can also do this: text. = input() word = input() def search(text, word): if word in text: return "Word found" else: return "Word not found" print(search(text, word))
30th May 2021, 10:37 AM
A͢J
A͢J - avatar
+ 2
you have a print statement in your last line but your function doesn't return anything so remove the last print function
30th May 2021, 9:04 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
Yeah thanks. I should have used return.The print(search(text,word)) was already given in the question.
30th May 2021, 10:52 AM
Joel Sebastian Jijo
Joel Sebastian Jijo - avatar
0
Thnx i did it and it worked.
30th May 2021, 9:05 AM
Joel Sebastian Jijo
Joel Sebastian Jijo - avatar
0
the alternative fix would be to return the result string, or even True or False (by modifying your print statement with a ternary like argument)
30th May 2021, 9:14 AM
visph
visph - avatar