Selection: if, elif and else

Selection lets a program make decisions. Python checks conditions from the top and runs the first block that is True.

Practise this lesson free (6 questions)

More tools

if, elif, else

Python checks each condition in order and runs only the first block whose condition is True.
else runs if none of them is True.
The colon and the indentation show which lines belong to each block.
mark = 72
if mark >= 70:
    print("A")
elif mark >= 50:
    print("B")
else:
    print("C")

Combining conditions

Use and, or and not to build conditions.
if age >= 13 and age <= 19: is True only for teenagers.
if day == "Sat" or day == "Sun": is True at weekends.

Nested selection

An if inside another if is nested. The inner if is only checked when the outer condition is True.
Always test the boundaries: what happens at exactly 70 or 50?
Worked example

What does the grade program print when mark = 50?

  1. mark >= 70 is False.
  2. mark >= 50 is True, so print B and skip the rest.

Answer: B

Key idea

if, elif and else choose which block runs; only the first True branch runs. Conditions use == != < > <= >= with and, or, not. Indentation shows the blocks.

Key words
Selection
Choosing which code runs using a condition, such as if, elif and else.
Indentation
Spaces at the start of lines showing which code belongs to a block. Python requires it.

All GCSE and International GCSE Computer Science key terms and definitions →

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 this print?
    mark = 64
    if mark >= 70:
    print("A")
    elif mark >= 50:
    print("B")
    else:
    print("C")

    Show the answer

    Answer: B

    64 >= 70 is False, but 64 >= 50 is True, so B is printed.

  2. What does this print?
    mark = 85
    if mark >= 70:
    print("A")
    elif mark >= 50:
    print("B")
    else:
    print("C")

    Show the answer

    Answer: A

    85 >= 70 is True, so A is printed.

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, 17 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

What do exam command words like explain and evaluate mean? →

Related lessons