0
function problem
why this code keeps printing the word "none" while there is nothing in code to print such a thing? text = input() word = input() def search(text,word): if word in text: print("Word found") else: print("Word not found") print(search(text,word))
1 Resposta
+ 2
Hi EMOJIMAN!
That's because there are two types of print statements in your code. First is inside function and second is outside function. But with print() inside a function, you don't need the outside one since the last print returns nothing. When a function doesn't return anything, it implicitly returns None.
So, you have to remove the print statement in the last line.
Alternatively, you can use return statement at end of function to return value.
So, it needs to be like 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))