The Big If = Nothing Printed?


The Big If

it behaved, and it passed the lesson, but It didn't print anything.

Shouldn't one of the conditions print something?

# Make sure that the_flying_circus() returns True
def the_flying_circus(): 
    if ( 3 < 5) and (2 == 2):
       return True
       print "hi"
    elif (3 != 2) or (5 > 1):
        return True
        print "hey"
        return True
        print "bye"


Because the return statement is before the print statement as soon as the condition is met and it hits the return statement it will exit.

If you move the print statement before the return statement then it should work like you were expecting.


Hi @ajaxmaster07306 ,

@mkordik made an important point. When a return statement is encountered while a function is executing, that function execution terminates. Therefore, a print statement following a return statement in the same block does not get executed. It is "dead code".

Also take into account the fact that defining a function does not cause it to execute. For it to execute, the function must be called. So, if you would like to see your the_flying_circus function print something, call it by adding a statement such as this at the end of your code ...


Be sure not to indent that statement, otherwise it will become part of the function definition, and will not be sufficient to initiate its execution.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.