15. The Big If


#1

Hey, im stuck on this level, it says "return outside function"

# Make sure that the_flying_circus() returns True
def the_flying_circus(): 100 >= 10
if the_flying_circus():  # Start coding here!
       print "100 is bigger than 10" # Don't forget to indent
        # the code inside this block!
elif the_flying_circus():
        print "100 Is Smaller Than 19"# Keep going here.
        return True
        # You'll want to add the else statement, too!


#2

This is what I did:

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    if 9 + 10 == 21:    
        return False
    elif (3 < 4) and (5 >= 5):
        return True
    else:
        print 'Something is wrong!'

#3

So, I can see your thought process going through defining this function; however, let's review the goal for this exercise.

We want to make the_flying_circus() return a value of True. In order to do that, we need to give it some sort of condition that returns True.

Some conditions that return true:

32 > 0
303 == 303
hi != hello

The goal of this exercise is to define the function so that it returns True on some satisfied condition. Your 100 >= 10 condition is certainly true, so let's put that under the function definition:

def the_flying_circus():
    if 100 >= 10:
        return True

Now, our function returns True because 100 is certainly greater than or equal to 10. Make sure you only define the function once; that is, you only need one the_flying_circus(): declaration.

For the elif: part, we can play around with statements that will not be satisfied. This is just practice so you understand how conditional flow works. For example:

elif 100 < 29:
    return False

The the_flying_circus(): function will still return True because this condition will never be satisfied, and will therefore never return False (the program stops after evaluating the if: statement and returns True. Even if it did evaluate the elif: statement, it would stop after testing whether 100 is smaller than 29, which is not the case).

So all together, we have:

def the_flying_circus():
    if 100 >= 10:
        return True
    elif 100 < 29:
        return False

Now, to finish the if/else block, we need an else: statement. See if you can come up with one on your own :slight_smile: but remember, this function should return True in the end.

Hope this improves your understanding!


#4

Tysm!!!!:grinning: This helped me lots, thank you again


#5

awesome thank you !!!


#6

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