GCSE · Computer Science · Edexcel · Spec 1CP2
Selection
Type the right password and you're in; type the wrong one and you're not. Same program both times. The only difference is which lines run. That's selection.
Computer Science · Selection
Guess the number: which way does the program go?
The same program runs twice: once with a right guess, once with a wrong one. Press Next and watch which box lights up at the diamond, and which one doesn't.
Predict first: when the guess is 7, which Output box never runs?
Output
Step 1: Run 1. A player is about to take a guess.
Use Next to follow the program one step at a time. Run 1 guesses 7; run 2 guesses 4.
Computer Science · Conditions
True or False? Test the conditions
score = 50. Does each condition evaluate to True or False?
Still to sort
True (0)
The comparison holds when score is 50.
Where the line is: With >= and <=, 'or equal to' is 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.
Every diamond holds a condition, and every condition comes out True or False. Here, score = 50. Read each condition out loud as a question, then sort it.
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. Step through three runs, mark = 85, then 55, then 30, and predict each output first.
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 password never checked at all?
Outer check: username → Inner check: password
3 possible routes through the log-in program.
The program: if username == "sam": then, indented inside it, if password == "pa55": print("Welcome") else: print("Wrong password"). The outer else: print("Unknown user").
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 used when a program has more than one possible path: it checks a condition and runs a block of code depending on whether the condition is True or False, so some lines never run.
- A condition is an expression that evaluates to True or False. It is built with a relational operator: == (equal to), != (not equal to), < (less than), <= (less than or equal to), > (greater than) or >= (greater than or equal to).
- 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. After the selection statement, the program carries on with the next line.
- With if, elif and else, conditions are checked one by one and only the block for the first True condition runs. You can use any number of elif blocks, and else is optional.
- In Python, == compares two values for equality; a single = assigns a value to a variable.
- Nested selection puts one selection statement inside another. An inner if placed in the outer if's block is only checked when the outer condition is True.
The big picture
Selection lets a program choose between paths. It checks a condition, an expression that is either True or False, and runs a block of code depending on the answer, so some lines are skipped. In a flowchart the choice is a diamond with True and False paths; in Python it is written with if, elif and else. Conditions are built with the relational operators ==, !=, <, <=, > and >=. In an if/elif/else, conditions are checked in order and only the first True condition's block runs. Selection statements can also be nested one inside another.
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 that every True condition in an if/elif/else gets its block run. Only the first True condition's block runs; the rest are skipped, even ones that would also be True. So the order of the conditions matters.
Memory hook
One question, one path, first True wins. And don't forget: 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 30 September 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.