GCSE · Computer Science · AQA · Spec 8525

Selection

Same code. Three different inputs. Three different outputs. The trick is a tiny question the program asks before it does anything: true or false?

Computer Science · Programming

Same code, different path

One tiny guessing program: if number == 7, print "You got it!"; elif number < 7, print "higher"; else, print "lower". Follow it when you type 3.

Before you press Next: you type 3. Which message will it print?

1 number = int(input())
2 if number == 7:
3 print("You got it!")
4 elif number < 7:
5 print("higher")
6 else:
7 print("lower")
8 print("Done")

Variables

number=3

Output

 

Step 1: You type 3, so number holds 3. Nothing has been decided yet. Press Next and watch where your 3 sends the program.

1 / 6

Press Next to step through the program. The highlighted line is the one being run. A block whose line never lights up never ran.

Step 1 of 6: You type 3, so number holds 3. Nothing has been decided yet. Press Next and watch where your 3 sends the program..

Computer Science · Programming

What does the program actually run?

Back to the guessing program: if number == 7 prints "You got it!", elif number < 7 prints "higher", and else prints "lower". You've just watched it print only higher, of the three messages, for 3.

Which idea is closest to what you think happens when the program runs?
How sure are you?

Computer Science · Programming

True, false, or not a comparison?

In Python, suppose age is 12. Pick a line, then pick where it belongs.

Still to sort

Evaluates to true (0)

The comparison is correct for age = 12.

Evaluates to false (0)

The comparison is wrong for age = 12.

Not a comparison: it's assignment (0)

It stores a value instead of asking a question.

Where the line is: In Python, a double == compares two values and a single = puts a value into a variable (other languages and pseudocode can use different symbols).

7 of 7 still to sort.

Computer Science · Programming

Find the line that breaks

This Python program should print Over 12 when age is above 12, and 12 or under otherwise. One line stops it working. Which one?

A student's program — which line goes wrong?

Computer Science · Algorithms

Trace table — dry run the code

One nested program, three values of mark. Watch which conditions get checked, and which never do. A blank cell means that condition was never checked.

1if mark >= 40:
2 if mark >= 70:
3 print("Merit")
4 else:
5 print("Pass")
6print("Done")
mark
mark >= 40
mark >= 70
Output
Press Start to run the first line.
·

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

Computer Science · Programming

Write your own selection

A program stores a competition score in a variable called points. Write a selection statement (in Python, pseudocode or another language) that prints Gold if points is 50 or more, prints Silver if points is 30 or more but below 50, and prints Bronze otherwise. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

How a program asks a true-or-false question and follows just one path.

What you need to know

  • Selection is for when a program has more than one possible path. It checks a condition, an expression that is true or false.
  • In a flowchart, the condition goes inside a diamond. Its true and false arrows lead to the two paths.
  • In Python, if comes first: the condition, a colon, then an indented block of code that runs only when it's true.
  • Add else, with its own colon and indented block, for the other path. You need an if and an else for two paths.
  • Have a gonumber is 3. The code says: if number > 5, add 5 to number; else take 5 away. What is number afterwards?

    -2

    3 > 5 is false, so the if block is skipped and the else block runs: 3 - 5 = -2. With if and else, one of the two blocks runs.

  • For three or more options, use if, elif and else. The conditions are checked one by one and the first true one runs.
  • Use as many elif blocks as you need. The else block is optional: leave it out and, if nothing is true, no block runs.
  • Have a goA chain has no else: if x < 5, then elif x < 10. What runs when x is 20?

    Nothing. No block runs.

    Both conditions are false, and with no else there is no other path to follow, so the program skips the whole chain.

  • A false condition's block is skipped. The program tries the next elif or else; with none left, it carries on after the selection.
  • Have a goSam bets you a biscuit that programs always run every line. score is 20 and print("Bonus") sits inside if score > 30. Does Bonus print?

    No. Bonus is skipped, so Sam owes you a biscuit.

    20 > 30 is false, so the block is skipped. Selection lets a program skip lines instead of running them all.

  • Relational operators compare two values: ==, !=, <, <=, >, >=. In Python, == checks for equal, while a single = assigns.
  • Common errors with selection are missing colons and wrong indentation.
  • Nested selection puts one selection block inside another. The inner condition is checked only if the main condition is true.

The big picture

Selection lets a program choose between paths. A condition, an expression that is true or false, decides which block runs. Use if for one block and else for the other path, or if, elif and else for three or more options, where the conditions are checked one by one and the first true one runs. Relational operators build conditions: == compares and a single = assigns. Selection blocks can be nested, and missing colons and wrong indentation are common errors.

Key points

1A block inside a selection statement runs only if its condition is true. If it is false, the block is skipped. The program moves on to the next elif or else if there is one; with none left, it carries on at the next line after the selection.
2if with else gives two paths. if, elif and else gives three or more: the conditions are checked one by one and the first true one runs, and else is optional.
3Relational operators (==, !=, <, <=, >, >=) compare two values and give true or false. In Python, == compares and a single = assigns.
4Nested selection puts a selection block inside another, so the inner condition is only checked when the main condition is true.
5In Python, missing colons and wrong indentation are common errors with selection statements.

Worked example

Problem

A speed checker runs: if speed > 70, print "Too fast"; elif speed == 70, print "On the limit"; else, print "Fine". What does it print when speed is 70?

⚠ Watch out

Thinking a program always runs every line from top to bottom. A program does follow a sequence, but selection lets it skip lines: only the block whose condition is true runs (in if/elif/else, the first true one), and the other blocks are skipped.

🧠

Memory hook

The diamond asks, one arrow answers: a condition is true or false, and only the path it picks runs.

✓

Check yourself

Cover the page. Can you say how a condition picks the path, write if, elif and else with their colons and indented blocks, and explain what happens to the blocks that don't run?

Flashcards

(14)
What is selection used for?
For when a program has more than one possible path to follow. A condition picks the path.
What is a condition?
An expression that evaluates to true or false.
Which flowchart symbol holds a condition?
A diamond. Its true and false arrows lead to the two paths.
What must follow the condition in a Python if statement?
A colon, then an indented block of code.
Which keyword gives the code for the other path?
else. The indented block under it runs on the other path.
When do you use elif?
When there are three or more options. Conditions are checked one by one and the first true one runs.
Is else compulsory in if/elif/else?
No, it's optional. Without it, if no condition is true, no block runs.
What happens to a block whose condition is false?
It is skipped. The program goes on to the next elif or else, or, if there is none, to the next line after the selection.
Name the six relational operators.
== (equal to), != (not equal to), < (less than), <= (less than or equal to), > (greater than), >= (greater than or equal to).
What is the difference between == and = in Python?
== compares two values and gives true or false. A single = assigns a value.
Name two common errors with selection statements.
Missing colons and wrong indentation.
What is nested selection?
A selection block placed inside another selection block.
When is the inner condition of a nested selection checked?
Only if the condition of the main selection block is true.
True or false: a program always runs every line.
False. Selection can skip some lines to follow a different path.

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 AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)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 13 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.