GCSE · Computer Science · Edexcel · Spec 1CP2
Selection
Two players, same game, same code. One guesses right and gets "You got it!", the other gets "Unlucky!". The only difference? Which lines ran. That's selection.
Computer Science · Selection
Guess the number: which way does the program go?
One program, run twice: a right guess, then a wrong one. Press Next and watch the diamond send you one way, then the other.
Before you press Next: when the guess is 7, which Output box never lights up?
Output
Step 1: Run 1. Player one is about to guess.
Press Next to move one step at a time. Run 1 guesses 7. Run 2 guesses 4.
Computer Science · Conditions
True or False? Test the conditions
score = 50. Read each condition out loud as a question. True or False?
Still to sort
True (0)
The comparison holds when score is 50.
Where the line is: <= and >= have 'or equal to' built in, so the boundary value itself makes them True.
False (0)
The comparison does not hold when score is 50.
Where the line is: > and < are strict: 50 is not greater than 50, and not less than 50 either.
Every diamond holds a condition, and every condition comes out True or False. Here score = 50, sitting right on the line. That's where the tricky ones live.
Computer Science · Algorithms
Trace table — dry run the code
Three possible outputs means three paths, so this program uses if, then elif (short for 'else if'), then else. We'll trace three runs: mark = 85, then 55, then 30. Predict each output before you step.
Ready when you are — step through one line at a time.
Computer Science · Nested selection
A decision inside a decision
Walk each route. On which route is the score never checked at all?
Outer check: lives → Inner check: score
3 possible routes through the game program.
The program: if lives > 0: then, indented inside it, if score >= 100: print("Level up") else: print("Try again"). The outer else: print("Game over").
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
How a program checks a condition and decides which code to run.
What you need to know
- Selection is for when a program has more than one possible path: it checks a condition, then runs a block depending on the answer.
- A condition is an expression that evaluates to True or False. Those are the only two answers.
- Relational operators compare two values: == equal to, != not equal to, < less than, <= less than or equal to, > greater than, >= greater than or equal to.
Have a gox = 7. Your friend is certain that x <= 7 is False, "because 7 isn't less than 7". Are they right?
No. x <= 7 is True.
<= means less than OR equal to, and 7 is equal to 7. Your friend is reading <= as if it were the strict < sign.
- In a flowchart, selection is a diamond-shaped decision symbol holding the condition, with one path labelled True and the other False.
- In Python, the block under if runs only when its condition is True. An else block runs when it is False.
- Whichever block runs, the program then carries on with the next line after the selection statement. The block that didn't run is skipped.
Have a goA robot vacuum runs: battery = 15, then if battery < 20: print("Going home") else: print("Cleaning"), then print("Beep") after it. What does the robot say?
Going home, then Beep.
15 < 20 is True, so the if block runs and the else is skipped. Beep comes after the selection statement, so it runs whichever path was taken.
- With if, elif and else, conditions are checked one by one, and only the block for the first True condition runs.
Have a goif x > 0: print("A") then elif x > 10: print("B"). Pick a whole number x that makes this print B.
There isn't one. B can never print.
Any x above 10 is also above 0, so x > 0 is True first and its block runs. The elif is never checked for those numbers.
- You can use any number of elif blocks, and else is optional. Without one, if every condition is False, no block runs.
- In Python, == compares two values for equality. A single = assigns a value to a variable.
- Nested selection puts one selection block inside another. The inner condition is only checked when the outer condition is True.
The big picture
Selection is how a program picks a path. It checks a condition (something that comes out True or False) and runs a block of code depending on the answer, so some lines get skipped. In a flowchart that's a diamond with a True path and a False path. In Python it's if, elif and else, with conditions built from ==, !=, <, <=, > and >=. With if/elif/else, the conditions are checked in order and only the first True one gets its block run. And you can put one selection inside another: that's nesting.
Key points
Worked example
Problem
Write a Python program that asks for a temperature (a whole number) and prints "Hot" if it is above 25, "Cold" if it is below 10, and "Mild" otherwise. Then test it with 30, 5 and 25.
⚠ Watch out
Thinking every True condition in an if/elif/else gets its block run. It feels fair: two True conditions, so why not both? But only the first True condition's block runs, and the rest are skipped. That's why the order of the conditions matters.
Memory hook
One question, one path, first True wins. And one = stores, two == compare.
Check yourself
n = 10. Is n >= 10 True or False? What about n > 10? And if the if and the first elif are both True for an input, which block runs?
Flashcards
(15)What is selection?
What is a condition?
How is selection shown in a flowchart?
When does the block under an if statement run?
When does an else block run?
What happens after a selection statement finishes?
In if/elif/else, several conditions are True. Which block runs?
Does an if statement need an else?
How many elif blocks can an if statement have?
In Python, what is the difference between = and ==?
What does != mean?
x = 5. Is x > 5 True or False? What about x >= 5?
What is nested selection?
An if is nested inside another if's block. When is the inner condition checked?
How do you trace a selection program for a given input?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 26 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.