Knowledge organisersDesigning, creating and refining algorithms
Create and use trace tables to follow an algorithm
A trace table is used to track the values of variables as an algorithm runs step by step. Each row represents one step of execution, and each column represents a variable. Trace tables help you understand what an algorithm does, check for logic errors, and predict the output of a program without actually running it.
print("The score is", score), the output is 'The score is 4' — not just 4. Do NOT include the comma from the print statement.staffID = surname + str(year), while staffID.length < 10: staffID = staffID + "x". With 'Kofi' and 2021: Kofi2021 → Kofi2021x → Kofi2021xx. Output on print line: 'ID Kofi2021xx'.while c < 100: c = c * 10. With c = 9: c becomes 90, then 900. Careful with loop bounds — the loop stops when the condition is False.# Trace this algorithm:
x = 1
for i in range(1, 4):
x = x * i
print(x)
# Trace table:
# i | x | Output
# ---|-----|-------
# 1 | 1 | 1
# 2 | 2 | 2
# 3 | 6 | 6