0

search engine challenge

Hey, help me out pls. I know that this way of solving is overcomplicated, but i wonder why this code not working? if you run it, it will additoinally print "None" on the new line. And i dont get were from it appeared? def search(text, word): if text.count(word) >=1: return(print("Word found")) else: return(print("Word not found")) text = input() word = input() print(search(text, word))

20th Apr 2021, 1:28 PM
Вячеслав Ершов
Вячеслав Ершов - avatar
4 Respuestas
+ 2
Вячеслав Ершов you had two outputs in your program: 1. The print in the search function (if or else branch) 2. The print on your last line where you call search function The first prints the desired output. The second prints the value that your search function returns. You are returning the return value of print. But print has no defined return value, so its return value is None, so the second print outputs "None"
20th Apr 2021, 5:02 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
Thanks, that worked. But I still do not understand why it print 'none'
20th Apr 2021, 2:44 PM
Вячеслав Ершов
Вячеслав Ершов - avatar
0
The print function generates output and doesn't return anything, so its return value is None. Your search function returns that None value and the last line prints it
20th Apr 2021, 2:42 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
Thanks a lot
20th Apr 2021, 5:16 PM
Вячеслав Ершов
Вячеслав Ершов - avatar