KS3 · Computer Science

Selection: making decisions in code

A theme park ticket program charges a 9-year-old 18 and a 14-year-old 25. Same program. How? It asks one question about age, gets True or False, and follows one path.

Computer Science · Selection

The ticket program’s fork

One visitor, aged 9. Step through and watch which price lights up, and which one stays dark.

Make a call before you press Next: does a 9-year-old pay 25 or 18?

TrueFalseStartage = 9age > 12?price = 25price = 18End

Output

 

Step 1: The ticket program starts.

1 / 5

Press Next and follow the lit path. Keep one eye on the other price box.

Step 1 of 5: The ticket program starts..

Watch out: In one run the program follows the True path or the False path. Never both.

Computer Science · Conditions

Make the call: True or False?

Pick a card, then pick its box. Commit first, then read why. Watch the pairs that use the same numbers.

Still to sort

Evaluates to True (0)

The comparison holds for those values.

Where the line is: When the two values are equal, >= and <= give True but > and < give False.

Evaluates to False (0)

The comparison does not hold for those values.

Where the line is: False is a proper result, not an error. It’s what sends a program down its other path.

8 of 8 still to sort.

A condition is a question your program can answer with True or False. Each card gives you a variable’s value and a condition. Your job: decide which.

Computer Science · Logical operators

Joining conditions: and, or, not

A login checks two things. A is “the username is admin”. B is “the password is password123”. For each row, tick the results that are True, then check your grid.

A True, B True
A True, B False
A False, B True
A False, B False

Computer Science · if and else in Python

Find the broken line in the PIN check

Here’s the fork in real Python. This ATM program asks for a PIN, then should output "Access Granted" if the PIN is 1234 and "Access Denied" if it’s wrong. The True path sits under if, the False path under else. One line is faulty. Which one?

A student’s ATM program — which line goes wrong?

Computer Science · Control structures

Where selection fits

Programs are built from control structures. Describe the three main ones, and name an example of selection. [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.

What you need to know

  • Selection is for when a program has more than one possible path: it checks a condition and picks one.
  • A condition is an expression that evaluates to True or False. With age = 9, age > 12 is False.
  • Relational operators compare two values: == equal to, != not equal to, <, <=, > and >=.
  • Have a goA ride needs height >= 120. Priya is exactly 120 cm. Does height >= 120 evaluate to True or False for her?

    True. She gets on.

    >= means greater than OR equal to, so 120 counts. Answering False treats >= as if it were >, which needs the value to be bigger.

  • In a flowchart, selection is a decision symbol with a True path and a False path coming off it.
  • In Python, the if block runs when the condition is True, and the else block runs when it is False.
  • Only one of those two blocks runs. You need both if and else when there are two possible paths.
  • Watch the equals signs: = assigns a value to a variable, == compares two values.
  • Have a goYour mate types if lives = 0: and declares Python is broken. Is Python to blame?

    No. It should be if lives == 0:

    A single = stores a value, so it can’t ask a question. == compares and gives True or False, which is what an if needs.

  • Python’s rules for if and else: lowercase, a colon after each, and the code inside indented.
  • and needs both conditions True, or needs at least one, and not flips True to False and back.
  • Have a gois_raining is True and is_cold is False. What does is_raining or is_cold give? And is_raining and is_cold?

    or gives True; and gives False.

    or only needs one True, so it’s True. and needs both True, and is_cold is False, so it’s False. Mixing them up flips both answers.

  • Selection is one of the three main control structures, alongside sequence and iteration.

The big picture

Selection is how a program chooses. It checks a condition, gets True or False, and runs one path. In Python that's if and else, and only one of the two blocks ever runs.

Key points

1A condition evaluates to True or False, and that result picks the path.
2if and else give two possible paths, but only one block runs each time.
3Use == to compare. Use = to assign.
4When the values are equal, >= and <= give True but > and < give False.
5and needs both conditions True; or needs at least one; not reverses.
6An if statement is an example of selection.

Worked example

Problem

A program has a variable called user. Write Python that outputs "Welcome back" if user is equal to the string "Alex", and outputs "Please sign up" if it is not.

⚠ Watch out

Two classic slips. One: writing = when you mean ==. = is assignment, so if pin = 1234: is a syntax error. Two: thinking the if block and the else block both run. They don't. True or False picks exactly one.

🧠

Memory hook

One equals puts it in. Two equals asks the question.

✓

Check yourself

age is 12. What does age > 12 evaluate to? What does age >= 12 evaluate to? Which of the two would send a program down its if block?

Flashcards

(14)
What is selection?
A program checks a condition that evaluates to True or False and follows one of two possible paths.
What is a condition?
An expression that evaluates to True or False.
What is a relational operator?
An operator that compares two values and produces True or False, such as == or <.
In a flowchart, what shows selection?
A decision symbol with a True path and a False path coming off it.
In Python, when does the else block run?
When the condition is False. The if block runs when it is True, and only one of the two runs.
What is the difference between = and == in Python?
= is assignment (it stores a value). == is comparison (it checks whether two values are equal).
Which operator means “not equal to”?
!=
What does >= mean?
Greater than or equal to.
Which Python rules apply to if and else syntax?
No capitals, a colon after the if and after the else, and the code inside each block indented.
When is A and B True?
Only when both A and B are True.
When is A or B True?
When at least one of A and B is True.
What does not do?
It reverses the answer: True becomes False and False becomes True.
Name the three main control structures.
Sequence, selection and iteration.
What does iteration do?
It runs the same lines of code more than once (looping).

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 KS3 Computer Science topics

See the full KS3 Computer Science curriculum →

How this lesson was checked. This KS3 Computer Sciencelesson 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 27 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.

Helpful guides for parents and students