The code doesn't work I need help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

The code doesn't work I need help

text = input() word = input() found = "Word found" nfound = "Word not found" def search(text, word): if text in word: return found else: return nfound print(search(text, word)) the code i wrote did not work. 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’s not. Sample Input "This is awesome" "awesome" Sample Output Word found please help solve the problem.

17th Mar 2021, 12:01 PM
Muhammad Ali
Muhammad Ali - avatar
3 Answers
+ 3
text = input() word = input() found = "Word found" nfound = "Word not found" def search(text, word): words = text.split() if word in words: return found else: return nfound print(search(text, word)) Hope above code will help you !!! It works for list check for tuple set dict (dictionary)
17th Mar 2021, 12:25 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
+ 2
thanks
17th Mar 2021, 12:33 PM
Muhammad Ali
Muhammad Ali - avatar
+ 2
def search(text, word): if word in text.split(): return "Word found" else: return "Word not found" print(search(input("enter text: "), input("enter word: ")))
17th Mar 2021, 4:41 PM
iTech
iTech - avatar