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)
4 Respostas
+ 4
def search(w, t):
if w in t:
print("Word found")
else:
print("Word not found")
+ 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.
+ 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)
+ 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.)