The Big if


I am stuck on the big if, on line 8 (look below)

The error message is "invalid syntax".

def the_flying_circus():
   if 2>1 and 3>=2 or True:    # Start coding here!
        # Don't forget to indent
        # the code inside this block!
    print "True"
    return True
    elif not True and 3==3 or 3!=4 or 3<=3:
        # Keep going here.
        # You'll want to add the else statement, too!
        return True
            print True 
            return True


First off, let's remove all the print statements for now, and just review the structure of an if statement:

def ___():
    if ___:

    elif ___:


The objective of the program is to return True. We can do this any way we wish, so long as one of the branches returns the expected value.

if "b" in "milk":
    return True
elif 1 ** 2 == 0:
    return True
    return True

As we can see, the program will return True, but by default since the else statement is executed. It's all silliness, but still works. Have fun with this exercise and play around with it. Don't bury yourself in anything complicated unless you are up to the challenge of solving any problems that arise.


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