+ 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
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.
+ 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.
+ 2
Jayakrishna🇮🇳 Thank you very much
+ 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
'''
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
'''