Dark theme

Firstly, we can make three versions of the if-statement:

We can have just an "if":

if decision == "N":
    print("This line done if condition true.")
print("This line always done.")

Or, we can have an "if-else", if we know either one or other is true:

decision = input("Do you want to enter? [Y,N]: ")
if decision == "N":
    print("This line done if condition true.")
else:
    print("This line done if condition isn't true.")
print("This line always done whatever.")

Or, if we've got more than one condition, we can have an if-else-if ladder:

decision = input("Do you want to enter? [Y,N]: ")
if decision == "N":
    print("This line done if N entered.")
elif decision == "Y":
    print("This line done if Y entered.")
else:
    print("This line done if something else entered.")
print("This line always done whatever.")

The last is useful, as sometimes people will push anything. Note the weird word elif!

[Home > Part 1 > Next]