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
| Word | What it means |
|---|---|
| Purpose | What an algorithm is for |
| Trace table | A table of the value of each variable after every step |
| Variable | A name that holds a value that can change |
| Output | What the algorithm shows or gives back |
| Logic error | The algorithm runs but gives a wrong answer |
| Debug | Find and fix mistakes |
| Loop | Steps 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 questionsYour 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?
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
failures = 0
limit = 3
while failures < limit:
failures = failures + 1
print("Locked after", failures)