Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Sequence and selection

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

The bus reader makes a choice

You tap your card on the bus. The reader asks itself some questions. Is this a child? Is this a student? Is it after 9am?

Each answer changes the price. A program does the same. It follows steps in order. At some steps it makes a choice. In this lesson you learn both.

Key words

WordWhat it meansExample
SequenceSteps that run one after another, from the top to the bottom.print, then print
SelectionA choice. The program picks one path.if age < 16
ConditionA question with the answer True or False.age < 16
ifRuns its lines only when the condition is True.
elifShort for else if. It tests another condition when the ones above were False.
elseRuns when no condition above was True.
match caseCompares one value with a list of patterns and picks the first that fits.
IndentationThe spaces at the start of a line. They show which lines belong inside the if.
FlowchartA picture of steps and decisions, drawn with symbols and arrows.

The cells students fill in are left blank in this preview.

Sequence: one step after another

A sequence is a list of steps that run in order. Python starts at the top and goes down. It does not skip a line unless you ask it to.

Order matters. You cannot take your ticket before you tap your card.

Try it: steps in order

Code: python
print("1. Tap your card")
print("2. The reader checks the fare")
print("3. Take your ticket")

# Swap line 1 and line 3, then run it again.
# The steps still run in order. But now the order is wrong.

Quick check: sequence

Have a go

Quick check: sequence

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Selection: the program chooses

Selection means the program chooses a path. It looks at a condition. A condition is a question with the answer True or False.

If the answer is True, one path runs. If it is False, the program takes the other path.

Flowchart symbols

SymbolWhat it means
Rounded boxStart or end
RectangleA process: something to do
Rectangle with double sidesA sub-process: a part that has its own flowchart
DiamondA decision: a question with two or more ways out
ParallelogramInput or output
Small circleA connector: joins to another part of the chart
ArrowThe flow: which step comes next

The cells students fill in are left blank in this preview.

Try it: if and else

Code: python
age = 14
if age < 16:
    print("Child fare: 1.00")
else:
    print("Adult fare: 2.50")

# Change age to 30 and run it again.

The lesson goes on

13 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.