The Big If has stumped me


#1



https://www.codecademy.com/courses/python-beginner-BxUFN/4/1?curriculum_id=4f89dab3d788890003000096




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?

Thanks.

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


#2

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"
    else:
        print "Success!"
        return True
    the_flying_circus()

#3

your last line:

the_flying_circus()

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


#4

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