+ 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?
9 Answers
+ 2
Use a return statement instead of printing. So that it only prints once.
+ 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.
+ 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.
+ 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â.
+ 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))
+ 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?
+ 1
Yes thank you DarX
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
0
DavX I switched it to (word,text)but I'm getting the same result