The IF Statement

The basic if-else statement in Python is as follows:

1
2
3
4
if <expression>:
    #write statement here
else:
    #write statement here

This video clip shows if statements being written in Python:

Here are some more examples of the if statement in action:

1
2
3
4
5
mark = int(input("What is your mark: "))
if mark >= 50:
    print("Pass")
else:
    print("Fail")
1
2
3
4
5
age = int(input("Enter your age: "))
if age >= 13:
    print("You are old enough to have a paper round")
else:
    print("You are too young to have a paper round")

Exercise

Write a function that asks the user how old they are. Tell them if they are old enough to vote. Then extend the program tell them how many years it is until they can retire (assume at age 65).