Python Code Challenges: Control Flow (Advanced) Number 4

Hello there,

I have tried the challenges without seeing the solution, but got confused.

https://www.codecademy.com/courses/learn-python-3/articles/advanced-python-code-challenges-control-flow

Create a function named movie_review() that has one parameter named rating.

If rating is less than or equal to 5, return "Avoid at all costs!". If rating is between 5 and 9, return "This one was fun.". If rating is 9 or above, return "Outstanding!"

The code

def movie_review(rating):
  if rating <= 5:
    return print("Avoid at all costs!")
  if (rating >= 5 and rating < 9):
    return print("This one was fun.")
  else:
    return "Outstanding!"

# Uncomment these function calls to test your movie_review function:
print(movie_review(9))
# should print "Outstanding!"
print(movie_review(4))
# should print "Avoid at all costs!"

Result

Outstanding!
Avoid at all costs!
None

my question is, where is “None” come from?

Thanks.

What happens when you remove the two print() that follow the return inside the function?

Hint: you don’t need to use print() inside the function b/c you’re returning a value. You have print() both inside AND outside the function. None happens when there is no value to return.

Ex:

def blah():
    return "huh?"

print(blah())

>huh?
-------------
def blah():
    print("what's happening?")

print(blah())

>what's happening?
>None
------------
def blah():
    print("what's happening?")

blah()

>what's happening?

See also: