+ 1

Search engine code project intro to Python

I think I have the right answer, but my output is "word not found." How can I change that?

27th Jan 2023, 8:25 PM
Bracha Notik
9 Respuestas
+ 2
Use a return statement instead of printing. So that it only prints once.
29th Jan 2023, 3:44 PM
DavX
DavX - avatar
+ 3
Please show your code. Pay attention to the spelling of the output strings: They must be exactly the same as in the task description.
27th Jan 2023, 8:32 PM
Lisa
Lisa - avatar
+ 2
Bracha, You need to search the input string to see if it contains the input word. If it does then print the word found text. If you show your attempt we can help steer you.
27th Jan 2023, 8:34 PM
DavX
DavX - avatar
+ 1
Bracha, your so close… Look at your calling of the function though, you define the function as “word, text” but are calling it with “text, word”.
29th Jan 2023, 3:41 PM
DavX
DavX - avatar
+ 1
Bracha, as you are soo close, here’s it working - look at the difference (using return instead of print) def search(text, word): if word in text: return('Word found') else: return('Word not found') text = input() word = input() print(search(text, word))
29th Jan 2023, 4:07 PM
DavX
DavX - avatar
+ 1
As your function didn’t return anything, the print statement had nothing to print (that’s why it was printing ‘None’) Hopefully that makes sense?
29th Jan 2023, 4:10 PM
DavX
DavX - avatar
+ 1
Yes thank you DarX
29th Jan 2023, 4:17 PM
Bracha Notik
0
this was my attempt. When I look at the comments everyone succeeded with the same answer def search (word,text): if word in text: print ("Word found") else: print ("Word not found") text = input() word = input() print(search(text, word)) my output: Word found None
29th Jan 2023, 2:54 PM
Bracha Notik
0
DavX I switched it to (word,text)but I'm getting the same result
29th Jan 2023, 4:03 PM
Bracha Notik