Write an if statement in the_flying_circus(). It must include:
●if, elif, and else statements;
●At least one of and, or, or not;
●A comparator (==, !=, <, <=, >, or >=);
●Finally, the_flying_circus() must return True when evaluated.
Don’t forget to include a : after your if statements!

This is my code which did not work

Make sure that the_flying_circus() returns True

def the_flying_circus():
if evaluated == 1:
return True
if 8 < 10 # Start coding here!
print True
# Don’t forget to indent
# the code inside this block!
elif evaluated == 0:
return not True or True
elif 8 > 10 # Keep going here.
print False
# You’ll want to add the else statement, too!
return -1:
print False
print the_flying_circus(1)


Start with the basic blocking, then fill in the missing bits.

if ____:
    # ____
elif ____:
    # ____
    # ____ 

Since the sky is the limit for this exercise, and the main requirement is that the function must return True, then just return True in all three branches.

if ____:
    return True
elif ____:
    return True
    return True

Now compose two conditional expressions that meet the requirements. Any kind of silliness is allowed.

if True > False:

elif True and not False:

Just make the expressions True.

On the other hand, write ridiculous expressions that are False, and only write a return line in the else: branch. You can leave the comments in the other two since they will never be seen by the interpreter.


ok what about the else:
does it get a code? this is my error

File “python”, line 9
SyntaxError: invalid syntax


else does not have a condition, just an action (return True).


I am trying to understand why else does not have an action


else has an action, but not a conditional.

if condition1:
    # conditional action
elif condition2:
    # conditional action
    # default action


Will it always be a default action? By the way, what do you do for a living? I like python programing and wanted to know if you know what type of jobs are out there to obtain for someone learning it


Yes, when it is included. We don’t need to have an else clause unless something must happen, no matter what.

Consider the following where we discount based on number of days.

def rental_cost(days):
    cost = 40 * days    # total cost before discount
    if days > 7:
        cost -= 50
    elif days > 3:
        cost -= 20
    return cost

There are two conditions to test for. If neither applies, return the total with no discount. In the above there is no default action in the if statement. The function returns a value in all cases.


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