+ 1

(pls help)python search engine

You’re working on a search engine. The given code takes a text and a word as input and passes them to a function called search(). The search() function should return "Word found" if the word is present in the text, or "Word not found", if it’s not. Sample Input "This is awesome" "awesome" Sample Output Word found

11th Apr 2023, 10:18 PM
M X
M X - avatar
7 odpowiedzi
+ 7
You are printing the return value of your search function and you are not returning a value, so its None. Instead of calling print in your search function you could return the string. e.g.: ... return "Word not found" ... btw it could be better to return a boolean value and handle the print outside depending on the return value.
11th Apr 2023, 10:26 PM
MrGrumpy
MrGrumpy - avatar
+ 2
M X , print of print function returns None. Instead => text= input() word= input() def search(text,word): if word in text: return 'Word found' else: return 'Word not found' print(search(text,word)) Hope it helps you.
12th Apr 2023, 6:51 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
TheWh¡teCat 🇧🇬 Pls avoid giving finished code as answer, because it makes the OP skip the most important part of learning. Prefer giving hints for the OP to find the solution instead.
13th Apr 2023, 1:53 AM
Emerson Prado
Emerson Prado - avatar
0
My code: text= input() word= input() def search(text,word): if word in text: print('Word found') else: print('Word not found') print(search(text,word)) My issue: Why my code keeps outputting: word found/not found + none.
11th Apr 2023, 10:20 PM
M X
M X - avatar
0
Emerson Prado , that's not the case here. M X posted his attempt, so I pointed his errors. I didn't give him the ready solution. When I try to help someone here, I always ask for his/her attempt. So I completely disagree with your post (I just mentioned his errors, according to his code).
13th Apr 2023, 6:54 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
TheWh¡teCat 🇧🇬 I mean the presence of the finished code, with the solution already implemented, in your answer. My recommendation was, instead, giving an explanation of it, then leave the imolementation for the OP.
13th Apr 2023, 2:06 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado , I think it's normal to write it, to show the errors. I didn't make any changes in logic of M X 's code and didn't use any other algorithm. The whole thing is that I replaced print function in search function with return statement to point his/her mistakes. So there's no major things to explain or to implement. Completely natural explanation, in my opinion, like many others I gave in Q&A section.
13th Apr 2023, 2:44 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar