Checking 30 laptops before lunch
A technician must test 30 laptops. For each one: switch it on, check the battery, and if it fails, put it on the red shelf.
The job has an order, a choice and a repeat. Every algorithm (a set of clear steps) is built from just these three actions.
Key words
| Word | What it means | Example |
|---|---|---|
| Sequence | Steps done one after another in order | |
| Selection | A choice: do a step only if a condition is true | if battery is low |
| Iteration | Doing steps again and again | |
| Condition | A test that is true or false | |
| Loop | Python code that repeats steps | |
| Flowchart | A picture of steps and choices joined by arrows |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can design an algorithm that uses sequence, selection and iteration.
Starter
Have a go
Starter
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Sequence: one step after another
Sequence means the steps run in the order you write them. The computer does step 1, then step 2, then step 3.
Order matters. "Switch on" must come before "check battery".
Try it: a sequence
print("1. Switch on the laptop")
print("2. Check the battery")
print("3. Record the result")
# Swap lines 2 and 3 and press Run. The order changes.
Selection: a choice
Selection means the algorithm chooses what to do. It asks a question. If the answer is yes it does one thing. If no, it does another.
In a flowchart, selection is a decision shape. In Python it is if and else.
Try it: a choice
battery = 15
if battery < 20:
print("Red shelf")
else:
print("Green shelf")
# Change battery to 80 and press Run.
Check
Have a go
Check
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.