+ 2

Can someone help me with python code?

I did the code, which prints "Word found" if input word was found in input text, but in end of output python writes "None", why? (If someone thinks that makes sense i'll say: i'm only learning python, i'm far from perfect programmer. That's my code: https://code.sololearn.com/c3LxqLBCWkHL/?ref=app

17th May 2022, 9:11 AM
Назар Марусич
5 ответов
+ 4
you do not have to put the function inside print() because it is already printing the result. the function have no return value, that is why none is printed.
17th May 2022, 9:21 AM
Bob_Li
Bob_Li - avatar
+ 3
Instead of print(search(text, word)) Just put search(text, word) #Назар Марусич this function is not returning anything so implicitly return None.. you don't need to print.
17th May 2022, 9:14 AM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 Thank you very much
17th May 2022, 9:16 AM
Назар Марусич
+ 1
def search(x, y): if y in x: print("Word found") else: print("Word not found") text = input() word = input() search(text, word) ''' input format: python is fun fun submit '''
17th May 2022, 9:18 AM
Bob_Li
Bob_Li - avatar
0
''' if you want to use print, you can modify your function so that it returns the string. ''' def search(x, y): if y in x: return "Word found" else: return "Word not found" text = input() word = input() print(search(text, word)) ''' input format: python is fun fun submit '''
17th May 2022, 9:34 AM
Bob_Li
Bob_Li - avatar