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))

10th May 2022, 12:25 PM
Camy
Camy - avatar
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
10th May 2022, 3:12 PM
Lothar
Lothar - avatar
+ 2
https://code.sololearn.com/crI04ZrxKMa8/?ref=app
10th May 2022, 3:24 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 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.
10th May 2022, 12:39 PM
Lisa
Lisa - avatar
+ 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))
11th May 2022, 12:51 PM
Sayida Saniya
Sayida Saniya - avatar