The Big If has stumped me


When I execute the code as listed below, I get the first error message. I thought that it would work correctly and output "success", since the "if"and "elif" statements are both false. When I first did this code (without the "return the_flying_circus()" at the end), I got the second error message. I have 2 questions:

  1. Why do I need this return statement at the end of the code?

  2. What in my code is recursive? Why is there a "recursion depth" being exceeded? Is it because my code does not resolve in some way?


def the_flying_circus():
    if 'apples' == 'bananas':    # Start coding here!
        print 'monkey butts'
    elif 99**1 != 10**2 - 1:
        print 'balls'
        print 'success'
        # Don't forget to indent
        # the code inside this block!
    return the_flying_circus()


Wow, I resolved the code myself! Apparently, I needed to put "return True" and "return false" in there as I went.

Here is the code that worked, with some of the values changed:

Still have one question: Why did the code not print the word "Success!" ? There was no output.

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    if False or False:    # Start coding here!
        return False
        print 'fail'
    elif 'False' == 'True':
        return False
        print "still fail"
        print "Success!"
        return True


your last line:


is the function call, it executes the function. So it should be placed outside/after the function (by having no indent)


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