The sheet that is flagged too late
A rule says "flag a sheet for review when it has 3 blanks". But a sheet with exactly 3 blanks is not flagged. Only a sheet with 4 is.
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?
prices = [20, 45, 30, 60]
biggest = prices[0]
for price in prices:
if price > biggest:
biggest = price
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
blanks = 0
limit = 3
while blanks < limit:
blanks = blanks + 1
print("Flagged at", blanks)