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?

TrueFalseStartRead in scorescore > 30?print("Bonus!")print("Gameover")End

Output

 

Step 1: Run 1. The program starts.

1 / 11

Press Next to follow the program round the diamond, once for each score.

Step 1 of 11: Run 1. The program starts..

Exam line: At a decision diamond, say the condition, say whether it is true or false, and say which arrow the program follows next.
Watch out: A false condition does not crash the program. The block is skipped and control carries on after the selection statement.

Computer Science · Python syntax

Python is fussy about two things

This program should add 5 to number if it is bigger than 5, and take 5 away otherwise. One line stops Python running it. Which one?

A classmate's program — which line goes wrong?

Exam line: After every if, elif or else: a colon, then an indented block.

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.

On Login starts. 2 branches to choose from.

Exam line: Nested selection: if the outer condition is false, the inner block is never reached.
Watch out: A wrong username never reaches the password question. The password check lives inside the username block.

Computer Science · Checking input

Blue is not blue

A program does colour = input() and then checks if colour == "blue":. The user types Blue, with a capital B.

What do you think happens at the check?
How sure are you?

Exam line: Convert input with lower() or upper() before you check it.

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

1A condition evaluates to True or False, and a block only runs when its condition is true.
2A decision diamond holds the condition, with arrows labelled true and false.
3Python selection: if, elif, else, each with a colon and an indented block.
4Multi-path selection runs only the first true block. Any number of elif blocks, else optional.
5Nested selection reaches the inner condition only when the outer condition is true.
6Use lower() or upper() on input so a single version is checked.

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?
Choosing which path a program follows. The program checks a condition and selects the path of action, used when there is more than one possible path.
What is a condition?
An expression that evaluates to True or False, for example score > 30.
What does the decision diamond in a flowchart contain?
A condition. The two arrows leaving it are labelled true and false, and the program follows one of them.
What happens to a block of code whose condition is false?
It is skipped, and control moves on to the line after the selection statement.
What must come after each if or elif condition in Python?
A colon, followed by an indented block of code.
What does elif add to an if statement?
A further condition, checked only if the conditions above it were false.
In multi-path selection, two conditions are true. Which block runs?
Only the first true one. The conditions are checked one by one.
How many elif blocks can a program have, and is else required?
As many elif blocks as it needs. The else block is optional.
What is nested selection?
A selection block placed inside another selection block. If the main condition is true, it leads on to the sub-conditions inside it.
In a nested login, when is the password checked?
Only after the username check is true, because the password check sits inside the username block.
What do the lower() and upper() methods do?
They convert what the user enters into all lowercase or all uppercase letters.
Why convert input before checking it in a condition?
So that a single version is checked, instead of every way a user might type it.
Write the line that stores what the user types in all lowercase, in a variable called colour.
colour = input().lower()

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 posted

More Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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.