GCSE · Computer Science · Edexcel · Spec 1CP2
Programming – selection
Same program. Same lines of code. With score = 20 one line gets skipped, and with score = 35 it doesn't. What decided?
Computer Science · Programming
One program, two runs
Run it with score = 20, then with score = 35. Watch which line gets skipped.
Before you step through: with score = 20, which line do you think gets skipped?
Output
Step 1: Run 1. The program starts.
Press Next to follow the program round the diamond, once for each score.
Commit first, then check
age = 12. Notice how many of the conditions are true for 12.
if age < 13: print("Child") elif age < 20: print("Teen") elif age < 65: print("Adult") else: print("Senior"). With age = 12, what gets printed?
Computer Science · Nested selection
A check inside a check
Walk a login. Pick a branch at each fork and see where the route ends up.
Username check → Password check
3 possible routes.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
How a program checks a condition and chooses which path to follow.
What you need to know
- Selection is used when a program has more than one possible path, and it picks the path by checking a condition.
- A condition is an expression that evaluates to True or False, such as score > 30.
Have a goQuick one: with number = 12, is the condition number > 12 True or False?
False
12 is not bigger than 12, so the expression evaluates to False. > means strictly bigger than.
- In a flowchart, the decision diamond holds the condition, and the arrows leaving it are labelled true and false.
- A block of code only runs if its condition is true. If not, it is skipped and control moves on to the line after the selection statement.
Have a goSam says: "If the condition is false, the program crashes." With score = 20 and if score > 30:, what actually happens to the indented block?
It is skipped, and the program carries on with the line after the selection statement.
A false condition is not an error. It just means that block does not run.
- In Python, selection uses if, elif and else. Each is followed by a colon and an indented block of code.
- Multi-path selection checks the conditions one by one and runs the block for the first one that is true.
- A program can have as many elif blocks as it needs, and the else block is optional.
Have a goA program has an if and an elif, but no else. The value meets neither condition. Which block runs?
None of them. Control moves on to the line after the selection statement.
A block only runs if its condition is true, and else is optional, so nothing catches the leftover case.
- Nested selection puts one selection block inside another, like checking a username first and then the password inside it.
- To check user input, lower() or upper() converts it to all lowercase or all uppercase, so a single version can be checked.
The big picture
Selection lets a program choose a path. It checks a condition, which is an expression that evaluates to True or False, and follows the matching path. A block of code only runs if its condition is true. In Python you write selection with if, elif and else, each followed by a colon and an indented block. In multi-path selection the first true condition wins. Selection can be nested, and lower() or upper() makes input checks reliable.
Key points
Worked example
Problem
Trace this program with temperature = 4. If temperature < 0 it prints "Ice", elif temperature < 10 it prints "Cold", else it prints "Mild". After all of that, a line that is not indented prints "Done". Which lines run, which are skipped, and what is printed?
⚠ Watch out
Thinking every true condition in an if/elif chain runs, or that every line of the program always runs. A block runs only if its condition is true, and in multi-path selection only the first true condition's block runs. Everything else is skipped, not run with an error.
Memory hook
Check it, take one path, carry on. The condition is the fork in the road, and the block on the path you didn't take simply never runs.
Check yourself
Cover the page. A value meets two conditions in an if, elif, elif, else chain. Which block runs, and where does control go next?
Flashcards
(13)What is selection?
What is a condition?
What does the decision diamond in a flowchart contain?
What happens to a block of code whose condition is false?
What must come after each if or elif condition in Python?
What does elif add to an if statement?
In multi-path selection, two conditions are true. Which block runs?
How many elif blocks can a program have, and is else required?
What is nested selection?
In a nested login, when is the password checked?
What do the lower() and upper() methods do?
Why convert input before checking it in a condition?
Write the line that stores what the user types in all lowercase, in a variable called colour.
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
- Global vs local variables
- Identifying and correcting program errors
- Primitive data types
- Programming – condition-controlled repetition
- Programming – count-controlled repetition
- Programming – iteration over data structures
- Programming – sequencing
- Programming arithmetic operators
- Programming logical operators
- Programming relational operators
- Reading, writing, analysing and refining programs
- Single entry/exit code blocks
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 21 November 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.