Great. Our if statement had only two options so far: either the test was passed or not. We can change this to add more possibilities.
john_age = 25
user_input = input('How old are you?')
user_age = int(user_input)
if user_age > john_age:
print('You are older than John.')
elif user_age == john_age:
print('You are as old as John.')
print('You are younger than John.')
Note that we added a new condition using
elif (short for else if) to check if the user's age equals John's age. We can also use
elif multiple times and include more conditions in the same way. As with
else, the code after
elif must be indented.
Also, we used two equals signs (
==) to check for equality. Remember, a single equals sign (
=) means 'assign the value of'. Confusing these two is a very common source of problems among beginner programmers.