GCSE Computer Science

Python selection โ€” if statements โ€” GCSE Computer Science

What is selection?

Selection is how a program makes decisions. Without it, code runs the same way every time regardless of what the user does or what the data contains. With selection, a program can take different paths depending on conditions. That's the difference between a calculator that always adds two numbers and one that does different things depending on which button you press.

In GCSE Computer Science, selection is tested in almost every question that involves any logic at all. Understanding if statements isn't one topic among many โ€” it's the foundation of everything else.

if, elif, else

score = 72

if score >= 90:
    print("Grade A")
elif score >= 70:
    print("Grade B")
elif score >= 50:
    print("Grade C")
else:
    print("Below pass")

Python checks conditions in order, from top to bottom. The first condition that is true runs its block โ€” the rest are skipped. If no condition is true, the else block runs. else is a catch-all: it has no condition of its own.

The order matters. If score >= 50 came first, a score of 72 would print "Grade C" โ€” even though it qualifies for "Grade B". Examiners test this deliberately.

Comparison and logical operators

age = 17
has_id = True

if age >= 18 and has_id:
    print("Entry allowed")
elif age >= 18 and not has_id:
    print("ID required")
else:
    print("Entry refused")

and requires both conditions to be true. or requires at least one. not reverses a boolean. These operators let you combine conditions โ€” and GCSE exams use all three. The most common mistake is confusing and with or: "entry allowed if age >= 18 AND has ID" means both must be true, not either.

What examiners actually test

Selection questions appear in two forms: trace through code with selection and state the output for given inputs, or write selection code that produces a specified behaviour. Both require understanding which branch runs for which input. The elif ordering question โ€” where changing the order of conditions changes the output โ€” is a favourite. Work through conditions in the order Python does: top to bottom, stopping at the first true condition.

Want structured Python lessons? Python Coach covers selection and 26 other lessons with 195 challenges โ€” free 60 teaching day trial.

Start learning →