symptom: The wrong result you can observe; cause: The reason the wrong result happens; base case: A case that returns without another recursive call
55-minute lesson sequence
0–5 · Answer the retrieval alone. Compare one reason.
5–15 · Teacher models the example. Students predict each next step.
15–40 · Build, trace and test the main tasks. Work alone first; compare after a checkpoint.
40–50 · Check results. Explain a test and repair one error. Use the extension only if ready.
50–55 · Complete the exit alone. Save the evidence for the next lesson.
Try before notes
For a nonnegative integer n, why does a recursive call using n-1 move toward n==0?
Build the idea
Debugging begins with a reproducible symptom. Write the expected result, run the smallest useful input and locate the first point where actual state differs. Changing many lines without a prediction makes the cause harder to identify.
For loops, check initial values, condition, update and return position. For recursion, check the base case, progress toward it and how returned values combine. A function can pass one example while failing a boundary or empty input.
A revision map should link each topic to evidence. Replace “I know files” with a specific claim such as “I can read blank lines safely under a valid-integer contract, shown by this test.” Choose the weakest evidence, not just the least favourite topic.
expected → trace → first difference → one repair → retest
↘ fresh transfer test
See the method
A faulty counter returns from inside the loop. For [24, 26] at limit 25, it returns 0 after seeing 24 and never checks 26. Moving return after the loop fixes the cause. Retest [24, 26], [25] and []. The tests then give 1, 1, 0.
def repaired_count(values, limit):
total = 0
for value in values:
if value >= limit:
total = total + 1
return total
Predict then reveal
A loop returns its running total after the first item. For values [2,6,8], what would a sum function incorrectly return?
Reveal reasoning
It returns 2 because the function exits before visiting 6 and 8. A correct complete sum is 16. Move the final return after the loop, then retest both this list and an empty list.
A recursive sum has base sum_to_n(0)=0 and returns n+sum_to_n(n−1). Trace n=2.
Reveal reasoning
Calls: 2→1→0. Base returns 0. Waiting call at 1 returns 1+0=1. Call at 2 returns 2+1=3. Showing returns matters as well as showing the downward calls.
Work one step together
Read the first task. Each learner predicts the first step privately. Compare the method, then complete one intermediate row or one code iteration together. Do not display a finished workbook answer.
Practice
Build a small test runner with assert statements for count_high and find_first_high. Include the empty list, equality, a later match and no match. Explain which test catches an early return.
Your turn
Complete the remaining steps of task 1 alone, then the next tasks. Predict before running code. Save your own evidence before comparing.
Practice
Build a small test runner with assert statements for count_high and find_first_high. Include the empty list, equality, a later match and no match. Explain which test catches an early return.
Trace sum_to_n(3) with base case n==0 returning 0 and recursive case return n + sum_to_n(n-1). Write call inputs and return values. Build a loop version and compare both for n=0, 1, 3. Inputs are nonnegative integers only.
Create a revision map with six headings: representation, logic, CPU, OS/control, cloud, Python files. For each heading, write one question you can answer and one example or test as evidence. Mark one priority for January.
Check and explain
A symptom is an observed wrong result; a cause is the mechanism producing it.
Point to the first step, row, condition or requirement that supports your answer. If results differ, find the first different state and repair one cause.
Show what you know
Why is a passing single test not proof that a program is correct for every input?
HL challenge when ready
Compare bubble sort and selection sort on [3, 1, 2]. State one complete result and an important input requirement for binary search afterward.
Week 7 homework
Show working. Keep code and output. Stop at 25 minutes and mark where you reached.
Make one revision card with three short parts. Convert decimal 46 to eight-bit binary and hex. Give the output of True AND NOT True. Name the CPU register holding the next instruction address.
A saved log has values [24, 25, 26]. Write the result of count_high(values, 25). Explain how a local controller can keep working when cloud access fails.
Choose the one revision-map area with the weakest evidence. Create one question and a checked answer for that area. Use only content already taught.
Spend about 3 minutes on each during practice time. Predict, run, change one thing, then explain. These prompts do not add homework.
A starter is runnable code to explore or complete. If the playground restores your saved code, the linked starter is selected in Example: use Load example when ready. Download your work before confirming replacement.
Prompt 1
Find and correct an off-by-one error in a count. Test an empty list too.
No imports needed.
Hint and starter code
Off-by-one means a result or boundary is one too high or too low.
# Off-by-one means a result or boundary is one too high or too low.
def count_items(values):
return len(values) + 1 # Your turn: repair
for values in [[], [24], [24, 25]]:
print(values, count_items(values))
Create a revision map linking a topic to one piece of evidence. Add a second topic.
No imports needed.
Hint and starter code
Use a real saved trace or test for your own evidence; this string is only an example.
# Use a real saved trace or test for your own evidence; this string is only an example.
evidence = {"Boolean logic": "four-row test"}
for topic, proof in evidence.items():
print(topic, proof)