0

What's wrong with my code?

You’re 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’s not. Sample Input "This is awesome" "awesome" Sample Output Word found text = input() word = input() def search(a,b): if b in a: print("Word found") else: print("Word not found") return search search(word,text)

9th Dec 2021, 10:40 PM
siviwe sam-sam
4 Answers
+ 4
def search(w, t): if w in t: print("Word found") else: print("Word not found")
9th Dec 2021, 10:58 PM
SoloProg
SoloProg - avatar
+ 4
Arguments in the same order as method parameters. I also changed the parameters to "w" and "t" to represent word and text and the problem was that it was text in word it should be word in text.
10th Dec 2021, 1:59 PM
SoloProg
SoloProg - avatar
+ 3
siviwe sam-sam You are returning function which doesn't make sense here because you have already printed value and also you can't return function like that. If you don't want to print inside function then return value and print function like: def search(a, b): if b in a: return "Word found" else: return "Word not found" print (search (word, text)
10th Dec 2021, 3:22 AM
A͢J
A͢J - avatar
+ 2
SoloProg the function is supposed to *return* the result, not print it. (However sololearn accepts incorrect solutions as long as they produce the expected output.)
10th Dec 2021, 12:32 AM
Simon Sauter
Simon Sauter - avatar