15. The Big If


#1

It keeps on saying "Oops, try again. the_flying_circus() returned the value None, did you forget to add a return statement?"

Here's my code:

def the_flying_circus():
if (10 == 10):
print "something"
elif (10 !=9) and (5 >= 5):
print "something else"
else:
print "another thing"

Can someone help me?


#2

Instead of using print you should use the return statement.

I will try to show you the difference with an example:

def my_func(number):
    if number  > 0:
        print "Hello"
    else:
        print "Goodbye"

This will print "Hello" or "Goodbye" depending on the function parameter to the console, but what if I want to use the printed string for something else? Maybe I want to save "Hello" or "Goodbye" inside a variable. That's what return is for.

def my_func2(number):
    if number > 0:
        return "Hello"
    else:
        return "Goodbye"

This new function will not print anything to the console, but return "Hello" or Goodbye". You can save a returned value in a variable:

foo = my_func2(13) # 13 > 0
print foo          # this will print "Hello"

You can also directly print my_func2(some_number):

print my_func2(-5) # This will print "Goodbye"

Hope this helps.