← ACARA Digital Technologies Years 9–10

Checking a trace against the real program output

Run the code with the same input you traced, then compare. If the real output differs from your trace, either the trace or the code has a mistake, so re-trace.

Understanding Checking a trace against the real program output in ACARA Digital Technologies Years 9–10

What it does: A matching trace and output means they agree for this input, which supports the trace and the code. A mismatch means re-tracing line by line to find the first point where your values and the program's values differ. A match only shows agreement for that one input. It does not prove the program works for all inputs, which is why you test a range of data. The code correctly adds 3 + 4 to get 7. Your hand calculation was wrong, so you fix the trace and not the program. Trace first so you predict the output independently. Changing the trace to fit the output hides mistakes instead of finding them.

Common mistakes: The trace gave 12, which comes from multiplying 4 by 3. The code adds instead, so the real output is 7 and does not match the trace. The line should be total = x * 3. The trace shows total building up to 12. This line replaces total each time, so the real output is 6 and does not match the trace. It should add: total = total + n.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 536–590) and word search (Modules 536–622).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
You traced a program using the input 5. Which input should you use when you run the real program to check your trace?
The same input, 5A different input, like 8, to test more
Matches
# traced with n = 3 n = 5 print(n * 2) # compare with trace
↓
The program was run with a different input (5) than the one traced (3), so the output cannot be compared with the trace
Applying
Meanings
Term
trace vs output
Meaning
Run the code with the same input you traced, then compare. If the real output differs from your trace, either the trace or the code has a mistake, so re-trace.
Practice
traced = 12
Testing
Gaps
print(expected actual)
Check Answer
Spots
1x = 4
2total = x + 3

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Scorpion' badge — Venom Debugger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. You traced a program using the input 5. Which input should you use when you run the real program to check your trace?
A. A different input, like 8, to test more
B. The same input, 5 ✓
To compare fairly, both the trace and the real run must use the same input. A different input gives a different output, so the comparison tells you nothing.
2. Your trace says the program prints 12. The real program prints 12 as well. What does this tell you?
A. The program is proven correct for every input
B. For this input, the trace and the code agree ✓
A match only shows agreement for that one input. It does not prove the program works for all inputs, which is why you test a range of data.
3. Your trace says the output is 10, but the real program prints 14. What should you do first?
A. Re-trace the code line by line to find the difference ✓
B. Assume the computer is wrong and ignore the output
A mismatch means either your trace or the code has a mistake. Re-tracing carefully is the first step to work out which one.
4. A mismatch between your trace and the real output means the code must have a bug.
A. False: the trace might have a slip ✓
B. True: the code is always the problem
You might have made a tracing slip, such as copying a value wrongly or skipping a line. The mismatch only tells you something is wrong, not where.
5. You re-trace and find you wrote total = 3 + 4 as 8 in your table. Which kind of mistake is this?
A. A tracing slip, because the code is fine ✓
B. A code error, because the output differed
The code correctly adds 3 + 4 to get 7. Your hand calculation was wrong, so you fix the trace and not the program.

Match the Pairs

print(total) # trace said 15, output 12 → The real output differs from the trace, so either the trace or the code has a mistake and needs re-tracing
n = int(input()) # trace used n = 4, run with 4 → Run the program with the same input you used in the trace so the two can be compared fairly
If the trace shows 10 but the program prints 10, the trace and the code agree, so no mistake is found for that input → # trace: total = 10 print(total) # output: 10
If the output differs from the trace, re-trace the code line by line to see where the trace and the program split apart → # trace: x = 6, output: x = 5 # re-trace from the first line
# traced with n = 3 n = 5 print(n * 2) # compare with trace → The program was run with a different input (5) than the one traced (3), so the output cannot be compared with the trace
# trace: 8, output: 6 # so the code must be wrong print(result) → Assuming the code is wrong without checking the trace; a mismatch could be a tracing slip, so re-trace before changing the code

Key Term

trace vs output
Run the code with the same input you traced, then compare. If the real output differs from your trace, either the trace or the code has a mistake, so re-trace.

Fill in the Blanks

1. expected = 12 actual = sum([2, 4, 6]) print(expected == actual)
Hint: Type the operator that checks whether your traced result is equal to the real output.
2. traced = 12 output = 10 if traced != output:
Hint: Type the variable that holds the real output of the program, so it can be compared with your trace.
3. n = 5 print(n * 2) print(n + 1)
Hint: Type the variable name that holds the same input value you used in your trace.
4. msg = "OK" if trace == output else "Retrace"
Hint: Type the keyword that gives the other result when the trace and output do not match.
5. def double(n): return n * 2 print(double(4))
Hint: Type the keyword that sends the result back so you can compare the real output with your trace of 4.

Spot the Error

Question 1
A x = 4
B total = x + 3
C expected = 12
D print(total == expected)
Line B — The trace gave 12, which comes from multiplying 4 by 3. The code adds instead, so the real output is 7 and does not match the trace. The line should be total = x * 3.
Question 2
A nums = [2, 4, 6]
B total = 0
C for n in nums:
D total = n
E print(total)
Line D — The trace shows total building up to 12. This line replaces total each time, so the real output is 6 and does not match the trace. It should add: total = total + n.
Question 3
A expected = 10
B actual = 3 + "7"
C if actual == expected:
D print("Match")
Line B — Adding the integer 3 to the string "7" causes a TypeError, so there is no real output to compare with the trace. The 7 should be a number: actual = 3 + 7.
Question 4
A x = 50
B y = x * 2
C print(y)
D # trace: 10
Line A — The trace was done with x = 5. Running the code with a different input gives 100, so the comparison is meaningless. Use the same input for both: x = 5.
Question 5
A trace = 6
B real = 2 * 3
C if real = trace:
D print("Same")
E else:
F print("Re-trace")
Line C — A single = assigns a value and is a syntax error in an if condition. To compare the real output with the trace, use ==: if real == trace:.

Student with a class code? Join your class →