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

Preview

SC 1.2: Follow it, find the fault, fix it

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

50 minutes

The account that locks too soon

A user types the wrong password three times. The rule says "lock after 3 failures". But the account locks on the second try.

The rule is an algorithm (a set of clear steps) and it has a fault. To find it you do what the computer does. You follow each step and write down every value.

Key words

WordWhat it means
PurposeWhat an algorithm is for
Trace tableA table of the value of each variable after every step
VariableA name that holds a value that can change
OutputWhat the algorithm shows or gives back
Logic errorThe algorithm runs but gives a wrong answer
DebugFind and fix mistakes
LoopSteps that repeat

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

By the end of this lesson

Note

I can use a trace table to find the output of an algorithm and spot an error in it.

Starter

Have a go

Starter

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.

First, find the purpose

To find what an algorithm is for, ask three questions. What goes in? What comes out? What happens in the middle?

Then say the purpose in one sentence.

Try it: what is it for?

Code: python
speeds = [20, 45, 30, 60]
biggest = speeds[0]

for speed in speeds:
    if speed > biggest:
        biggest = speed

print(biggest)

# What is the purpose? Change the numbers and press Run.

A trace table gives the output

A trace table has one column for each variable and one row for each step. Follow the algorithm one step at a time. Write the new value of each variable every time it changes.

The last row shows the output.

An algorithm to trace

Code: python
failures = 0
limit = 3

while failures < limit:
    failures = failures + 1

print("Locked after", failures)

The lesson goes on

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