Python: making decisions with if
Programs become useful when they can make decisions. In Python, if, elif and else choose which code runs.
Comparison operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
| == | equal to | 5 == 5 | True |
| != | not equal to | 5 != 3 | True |
| < | less than | 2 < 1 | False |
| > | greater than | 7 > 3 | True |
| <= | less than or equal to | 4 <= 4 | True |
| >= | greater than or equal to | 3 >= 5 | False |
if, elif, else
if score >= 70:
print("Distinction")
elif score >= 50:
print("Pass")
else:
print("Try again")
Python checks each condition from the top. The first one that is True runs, and the rest are skipped.
else runs only if nothing above it was True.
The indentation (the spaces at the start of a line) shows which lines belong to each part.
Common mistakes
Forgetting to indent the code inside.
Putting conditions in the wrong order: check the highest score first, or a high score would only get Pass.
What does the program print when score = 65?
score = 65
if score >= 70:
print("Distinction")
elif score >= 50:
print("Pass")
else:
print("Try again")
- Is 65 >= 70? No.
- Is 65 >= 50? Yes, so print Pass and skip the rest.
Answer: Pass
if checks a condition; elif checks another if the first was False; else catches everything left. Use == to compare, end the line with a colon and indent the code inside.
- Elif
- Short for "else if" in Python: it checks another condition when the ones before it were False.
- AND
- A Boolean operator that gives True (1) only when both inputs are True.
- Condition
- An expression that is either True or False, such as score > 50, used in if statements and while loops.
- Not “=”. = assigns a value; it does not compare.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
What does the program print when score = 95?
score = 95
if score >= 70:
print("Distinction")
elif score >= 50:
print("Pass")
else:
print("Try again")Show the answer
Answer: Distinction
95 >= 70 is True, so Distinction.
What does the program print when score = 51?
score = 51
if score >= 70:
print("Distinction")
elif score >= 50:
print("Pass")
else:
print("Try again")Show the answer
Answer: Pass
51 >= 70 is False, but 51 >= 50 is True, so Pass.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
Facts checked against the sources below, 27 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.