Python: making decisions with if

Programs become useful when they can make decisions. In Python, if, elif and else choose which code runs.

Practise this lesson free (6 questions)

More tools

Comparison operators

Remember: = stores a value, == compares two values.
OperatorMeaningExampleResult
==equal to5 == 5True
!=not equal to5 != 3True
<less than2 < 1False
>greater than7 > 3True
<=less than or equal to4 <= 4True
>=greater than or equal to3 >= 5False

if, elif, else

score = 65
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 the colon : at the end of the if line.
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.
Worked example

What does the program print when score = 65?
score = 65
if score >= 70:
    print("Distinction")
elif score >= 50:
    print("Pass")
else:
    print("Try again")

  1. Is 65 >= 70? No.
  2. Is 65 >= 50? Yes, so print Pass and skip the rest.

Answer: Pass

Key idea

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.

Key words
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.

All KS3 Computing key terms and definitions →

Common mistakes
Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. 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.

  2. 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.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Facts checked against the sources below, 27 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons