+ 1
Why is my code failing to complete some test cases?
My python code for a search engine project Isn't producing the correct output for the second test case and I can't figure out what is wrong. Any help please? https://www.sololearn.com/learning/eom-project/1157/1022
4 ответов
+ 3
Henry Viyuyi
We can't see your code through that link so attach your code with question.
+ 1
Can you please attach your code attempt.
The link to the challenge makes my phone crash
+ 1
David García Prados the solutions in that thread are wrong. They define a function that *prints* the result. However the task is to write a function that *returns* the result.
Those codes will pass the test cases, but only because solo learn only checks the output, it doesn't check whether or not your code produces that output in the right way.
[Edit: the answer I'm referring to is deleted. I'll let this answer stay anyway since it seems that a lot of people use print instead of return in the function definition for this task. ]
+ 1
Ok, Simon. Added my solutions.
Using lambdas:
text = input()
word = input()
search = lambda text, word : 'Word found' if word in text else 'Word not found'
print(search(text, word))
Without lambdas:
text = input()
word = input()
def search(text,word):
return 'Word found' if word in text else 'Word not found'
print(search(text, word))