-1
def search(text, word):
    if word in text:
        print("Word found")
    else:
        print("Word not found")

text = str(input())
word = str(input())

print(search(text,word))

This code returns the following:

"Word found \
none"

When I use this entry:

"This is some sample text" \
"some"

The desired output would be: "Word found"

Adrian
  • 468
  • 2
  • 6
  • 15

1 Answers1

0

Give this a try. You aren’t returning a value in your function.

def search(text, word):
    if word in text:
        print("Word found")
        return word
    else:
        return "Word not found"

text = str(input())
word = str(input())

print(search(text,word))
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • This is on the right track, but the two return statements return different things, which is bad design. OP said the output should be just `Word found`, so remove the `return word` and just do `return "Word found"` instead. – wjandrea Jun 25 '22 at 02:17
  • Good catch! My bad! – Ben Palladino Jun 25 '22 at 02:18