+ 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 Réponses
+ 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