How to remove "None" from output

This is an assignment. I have everything correct EXCEPT the last thing it
prints is None.
Test input “This is awesome”
Test input “is”
Test input (any word not in text)

How do I get rid of the None that prints?

Thanks

def search(text, word):
    if word in text:
        print('Word found')
    else:
        print('Missing ')

text = input()
word = input()

print(search(text, word))
def search(text, word):
    if word in text:
        print('Word found')
    else:
        print('Missing ')
    return word

search() has no return statement, so it will by default return None.

When you call the search at the bottom, it prints out either Word found or Missing and then it returns None to the caller.

The None is passed to the print on that last line and is printed.

Alternatives:

  • Don’t print the search on the last line, just call search (with no print surrounding).
  • Don’t print from the search function. Have it return the string instead.
2 Likes

Thank You, not only for the answer, as that is important, but explained why it did what it did. I had not run into that yet in my studies. Or it didn’t sink in. I keep trying.

1 Like