0
Please what is wrong with this code (python)
def search(text , word): for x in text: if x==word: return ('Word found') else: return ('Word not found') text = input() word = input() print(search(text, word))
4 Respuestas
+ 2
Camy ,
there might be an issue by only using ... if word in text: ..., because this can also find substrings of a word.
see the 2 samples in the file ( as far as i know the code coach does work with the above version, but it is not correct from my point of view)
https://code.sololearn.com/cwAf26H6295I/?ref=app
+ 2
https://code.sololearn.com/crI04ZrxKMa8/?ref=app
+ 1
x is a single character when you iterate through text.
== compares for equality, so x == word will only be true, if they are the same
The task requires you only to check
if word in text
Re-read the lessons and pay attention to the "in" operator.
+ 1
If it is search engine project then code goes like this
text =input()
word =input()
def search(text,word):
if word in text:
return "Word found "
else:
return "Word not found "
print(search(text,word))