0

Why does my code give 2 outputs when it's supposed to be only 1 output

The code is text = input() word = input() def search (): if word in text: print("Word found") else: print("Word not found") print(search()) The problem is this let's say the input is Sololearn is good is The output answers word found but in the second line of the output it says none even though it's not supposed to be there, what should I do?

9th Jun 2021, 2:30 PM
Da GD Bot
Da GD Bot - avatar
4 Respostas
+ 5
Hi! Simple delete print() and leave search()
9th Jun 2021, 2:38 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Da GD Bot Because you are not returning anything in function so if you print function then None will return. So don't print function just call function like: search ()
9th Jun 2021, 2:46 PM
A͢J
A͢J - avatar
+ 1
def search (): if word in text: return ("Word found") else: return ("Word not found") print(search()) replaced print with return will give you word found / word not found based on input.
9th Jun 2021, 2:51 PM
Nanda Balakrishnan
+ 1
Aight it's done thanks guys
9th Jun 2021, 2:57 PM
Da GD Bot
Da GD Bot - avatar