0

help my code does not iterate

The code takes text and word as input and passes them to a search() function. should return "Word found" if the word is text, or "Word not found" if it is. https://code.sololearn.com/cYjOUfPLAjv8/?ref=app

29th Jan 2023, 7:23 PM
Abg. Mosquera.
Abg. Mosquera. - avatar
10 Respuestas
+ 2
Try this: def search (x,y): for i in x: if i == y: return ("Word found") else: return ("Word not found") text = input() word = input() print(search(text, word)) i only remove split from your code hope it helps you ^_^
31st Jan 2023, 12:32 PM
omer kemal
omer kemal - avatar
+ 2
You don't need to split() anything and you don't need a loop. Just check: if word in text
29th Jan 2023, 7:25 PM
Lisa
Lisa - avatar
+ 1
Thanks
5th Feb 2023, 5:26 AM
Abg. Mosquera.
Abg. Mosquera. - avatar
0
the challenge asks me this: You are working on a search engine. Watch your back Google! The given code takes a text and a word as input and passes them to a function called search(). The search() function should return "Word found" if the word is present in the text, or "Word not found" if it is not. input example "This is incredible" "amazing" output example found word Define the function search(), so that the given code works as expected.
29th Jan 2023, 9:48 PM
Abg. Mosquera.
Abg. Mosquera. - avatar
0
and my code only delivers the second output but it doesn't deliver the first and to meet the challenge I must deliver both
29th Jan 2023, 9:52 PM
Abg. Mosquera.
Abg. Mosquera. - avatar
0
Again: You do not need the loop, you only need to test "if word in text" and return the corresponding string.
29th Jan 2023, 9:53 PM
Lisa
Lisa - avatar
0
Ok
29th Jan 2023, 11:37 PM
Abg. Mosquera.
Abg. Mosquera. - avatar
0
For next time please, avoid wriring code in the post tags, tags has their own purpose for the forum's search engine. https://code.sololearn.com/W3uiji9X28C1/?ref=app
30th Jan 2023, 4:51 AM
Ipang
0
Thanks for the support of both of you. I really attribute the information to myself. I realized that you were drowning me in the gorilla.
30th Jan 2023, 12:02 PM
Abg. Mosquera.
Abg. Mosquera. - avatar