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?

TrueFalseStartsecret = 7Input guessguess == secret?Output "Yougot it!"Output"Unlucky!"Output "Gameover"End

Output

 

Step 1: Run 1. Player one is about to guess.

1 / 14

Press Next to move one step at a time. Run 1 guesses 7. Run 2 guesses 4.

Step 1 of 14: Run 1. Player one is about to guess..

Exam line: At a decision, say three things: the condition, whether it is True or False for this input, and which path is taken.
Watch out: A decision doesn't stop the program. Here, after the True box or the False box, both arrows lead on to Game over, so that step runs either way.

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.

7 of 7 still to sort.

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.

Watch out: Right on the boundary, > and >= give different answers. So do < and <=. One little = sign flips the result.

Computer Science · Operators

Find the broken line

Here's the guessing game from the flowchart, typed up in Python by a student. The diamond became if, and the False arrow became else. One line uses the wrong operator. Which one?

A student's program — which line goes wrong?

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.

1mark = int(input("Mark: "))
2if mark >= 70:
3 print("Distinction")
4elif mark >= 50:
5 print("Merit")
6else:
7 print("Not yet")
8print("Done")
mark
condition
result
Output
Press Start to run the first line.
·

Ready when you are — step through one line at a time.

Computer Science · Selection

Does the order matter?

A student writes the grading program with the first two conditions the other way round: if mark >= 50: print("Merit"), then elif mark >= 70: print("Distinction"). No else. The user types 85.

What does this program print? Pick the idea closest to what you honestly think right now.
How sure are you?

Exam line: When tracing if/elif/else, stop at the first True condition. Anything after it is not checked.

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.

On End of a level. 2 branches to choose from.

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").

Watch out: Indentation shows what's inside what. The score check is indented inside the lives block, so it belongs to the lives > 0 True route only. A huge score won't help you with no lives left.

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

1Selection = check a condition, then follow one path. In an if/elif/else, at most one block runs, so some lines are skipped.
2A condition is always True or False.
3Flowchart decision = diamond holding the condition, with a True path and a False path.
4if runs its block when True; else runs its block when False; then the next line after the selection statement runs.
5if/elif/else: checked top to bottom, first True wins, any number of elifs, else is optional.
6== compares, = assigns.
7Nested: an inner check inside an if's block is only reached when the outer condition is True.
8To trace: for each input, record each condition checked, True or False, which block runs and the output.

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?
Choosing which path a program takes: it checks a condition and runs a block of code depending on whether it's True or False, so some lines are skipped.
What is a condition?
An expression that evaluates to True or False.
How is selection shown in a flowchart?
A diamond-shaped decision symbol containing the condition, with one path labelled True and the other False.
When does the block under an if statement run?
Only when the if's condition is True.
When does an else block run?
When none of the conditions above it are True.
What happens after a selection statement finishes?
The program carries on with the next line after it, whichever block ran.
In if/elif/else, several conditions are True. Which block runs?
Only the block for the first True condition. Conditions are checked in order, top to bottom.
Does an if statement need an else?
No, else is optional. Without one, if no condition is True, no block runs and the program carries on.
How many elif blocks can an if statement have?
Any number.
In Python, what is the difference between = and ==?
= assigns a value to a variable. == compares two values and gives True if they are equal.
What does != mean?
Not equal to. It's True when the two values are different.
x = 5. Is x > 5 True or False? What about x >= 5?
x > 5 is False (5 isn't greater than 5). x >= 5 is True (5 is equal to 5).
What is nested selection?
A selection block placed inside another selection block.
An if is nested inside another if's block. When is the inner condition checked?
Only when the outer condition is True. If the outer condition is False, the inner if is never reached.
How do you trace a selection program for a given input?
Check each condition in order, note whether it's True or False, and record which lines run and what is output.

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 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.