DoAssignment study guide
B3.3 · Trace a program to find an error
Learn to trace a program to find an error through clear examples and targeted practice.
Ontario Grade 10 Computer Science
Introduction to Programming
ICS2O study topic B3.3: follow instructions, record what happens, and compare it with the intended result
What you will learn
- Explain tracing as following a program step by step for stated input.
- Identify a program’s input, process, and output.
- Record values and decisions to locate an error.
- Trace a proposed correction with the same input.
State the purpose and identify input, process, and output
- State the intended behaviour before following the code.
- Use the input given in the problem or scenario.
- Compare the traced output with the expected output.
Follow instructions and record changes
- Record values when they are assigned or changed.
- Evaluate each decision using the exact input.
- For a loop, include the update and the condition check that ends it.
Use the trace as evidence
- Name the instruction responsible for the mismatch.
- Support your explanation with a recorded value or decision.
- Trace a proposed correction separately from the original code.
A repeatable tracing routine
- Trace the original code before changing it.
- Keep the expected output distinct from the traced output.
- Explain a mismatch using evidence from the trace.
Trace of the reminder loop as written
| Counter at condition | Condition counter <= 4 | Reminder displayed | Counter after increase |
|---|---|---|---|
| 1 | True | Yes | 2 |
| 2 | True | Yes | 3 |
| 3 | True | Yes | 4 |
| 4 | True | Yes | 5 |
| 5 | False | No; loop stops | — |
Worked example
A total leaves out the first price
Follow the input values through the assignments to the displayed total.
Python 3
first_price = 5
second_price = 2
total = second_price
print(total)- Set the purposeThe inputs are 5 and 2. The process should add both prices, and the expected output is 7. The final instruction displays the value named total.
- Follow the assignmentsThe first assignment gives first_price the value 5, and the second gives second_price the value 2. The next assignment copies second_price into total. It does not add the first price, so total becomes 2 and that is what the program displays.
- Locate and check a correctionThe assignment to total is the error because it uses only the second price. A correction is to assign the sum of first_price and second_price to total. Following that changed instruction on paper gives 7 for these inputs; this is a trace, not a claim that the code was run.
Worked example
A decision misses the boundary age
At age 12, the written condition is false. Yes and No show the two possible branches.
Python 3
age = 12
if age < 12:
print("Child entry")
else:
print("Other entry")- Identify the expected outputThe input is age 12. The stated rule includes age 12 among ages 12 and under, so the expected output is “Child entry.”
- Evaluate the written conditionThe code asks whether age is less than 12. At age 12, that condition is false, so the program follows the else branch and displays “Other entry.”
- Check a correctionThe condition leaves out the boundary age. Changing it to age <= 12 includes 12. For the same input, the condition is true and the program follows the child-entry branch.
Worked example
A reminder loop repeats too many times
The Yes path displays the reminder and updates the counter before returning to the decision. No ends the loop.
Python 3
counter = 1
while counter <= 4:
print("Check your notes")
counter = counter + 1- Trace each repetitionThe counter starts at 1. The condition counter <= 4 is true at 1, 2, 3, and 4. At each of those values, the program displays the reminder and increases the counter by 1. The message is therefore displayed four times.
- Check why the loop stopsAfter the display at counter 4, the counter increases to 5. The condition is then false, so the loop stops. The extra display happens because the condition allowed the counter value 4.
- Check a correctionChanging the condition to counter < 4 allows displays at counter values 1, 2, and 3. After the counter increases to 4, the condition is false, so the loop ends without a fourth display.
Common mistakes and how to avoid them
Lesson summary
- Tracing means following code step by step with specific input.
- Identify input, process, and output before comparing behaviour with purpose.
- Record changing values and evaluate decisions as written.
- Trace each loop repetition, including the final condition check.
- Use a traced value or decision as evidence when explaining an error.
Check your understanding
Question 1
- It displays “Adult” because the condition includes 18.
- The condition is false, so it follows the other branch; the test excludes 18.
- It displays both messages.
- The code cannot be traced without running it.
Show answer and explanation
Question 2
- Two times
- Three times
- Four times
- It does not stop.
Show answer and explanation
Question 3
- Change the line that looks unusual.
- Use the stated input and follow the instructions in order.
- Assume the output and work backwards.
- Skip value changes and inspect only the final line.
Show answer and explanation
Key terms
- Trace
- Follow a program’s instructions step by step with specific input and record what happens.
- Input
- Information a program receives.
- Process
- The work carried out by a program’s instructions.
- Output
- Information a program displays or produces.
- Condition
- A true-or-false question in a program that affects which instruction follows.
- Trace table
- A table for recording important values and decisions while following a program.
Continue through ICS2O
View the complete ICS2O Ontario Grade 10 Computer Science curriculum and lessons
Tutor support for B3.3 · Trace a program to find an error
Working on B3.3 · Trace a program to find an error in ICS2O? Bring the question and your own attempt. In a live session, you can trace a small input step by step, compare expected and actual output, and test an edge case. Ask about the first step that does not make sense, then try a similar question yourself.
Explore coding tutoring · Request an eligible free 30-minute introduction. Your request is matched by subject and language; a tutor must accept before a time is confirmed.
برای مبحث B3.3 · ردیابی برنامه برای یافتن خطا در درس ICS2O، سؤال و تلاش خود را همراه بیاورید. در جلسه میتوانید یک ورودی کوچک را گامبهگام دنبال کنید، خروجی مورد انتظار و واقعی را مقایسه کنید و یک حالت مرزی را بیازمایید. راهنمای معلم برنامهنویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقهای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی میشود.
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 10 Computer Science (ICS2O), expectation B3.3. It is a study resource, not an official curriculum publication.
Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.