The Big If


#1

Hey !

I am stuck and I've read different replies and I am still following. Can anyone break it down and help me understand?

I am just stuck.

T


#2

Please post the exercise link, your code, and the problem you are facing. Thanks!


#3

This is the excercise

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    if ________:    # Start coding here!
        # Don't forget to indent
        # the code inside this block!
    elif ________:
        # Keep going here.
        # You'll want to add the else statement, too!

Here are the instructions:

Write an if statement in the_flying_circus(). It must include:

  1. if, elif, and else statements;
  2. At least one of and, or, or not;
  3. A comparator (==, !=, <, <=, >, or >=);
  4. Finally, the_flying_circus() must return True when evaluated.
  5. Don't forget to include a : after your if statements!

It should look easy but somehow I can't seem to get it right. I used the hint (see below) but I'm still stuck.

HINT:
Be careful with your indentation—the_flying_circus() is a function (which we'll get to in the next unit), and as you can see from the comment, function blocks are indented the same way if, elif, and else blocks are.

Your code should look something like this:

def the_flying_circus():
    if condition:
        # Do something!
    elif condition:
        # Do something else!
    else:
        # Do yet another thing!

#4

Please always format your code (tutorial) from next time! Thanks! :slightly_smiling:

Here is a breakdown of instructions:

  1. Use an if-elif-else ladder like the one stated in the hints.
  2. A condition must consist of and, or or not logical operator. Sample condition: 1 > 2 or 2 > 1
  3. Use a comparator (==,!=,<, <=, >, or >=) in any condition, like: 1 >= 0
  4. Ensure to make your conditions in such a manner that the flying_circus method when called returns True
  5. That's just a reminder for your syntax:

if condition: # colon here
    # do stuff!
elif condition2: # colon here
    # do more stuff!
else: # colon here
    # do even more stuff!

In the end, it's all up to you on what conditions you come up with. You can do it anyway you like, just ensure that it follows the criteria given in the instructions.

Hope it helps! :slightly_smiling: