The idea
Start with the smallest experiment that reproduces the surprise. Read the last line of the traceback, then look at the line number it names. Say what you expected and what happened instead. Change one thing, run again and compare. Keep a working version before a bigger experiment. This is the same habit as checking a clue rather than trusting your first theory.
A tiny experiment
clues = 2
print("Before:", clues)
clues = clues + 1
print("After:", clues)
assert clues == 3Reveal the expected output
Before: 2 After: 3
Read it one step at a time
- The first print shows the value before the change. These temporary messages help you follow state.
- The second print checks the result of one step, not just the final outcome of a long program.
- assert checks a claim. A true condition is silent; a false one raises AssertionError. It is useful for experiments and tests.
Make one change
Change the increment to 2. Predict the prints and whether the assertion succeeds.
Check your thinking
It prints Before: 2 and After: 4, then raises AssertionError.
Keep following the trail
- Activity 01: Your first message
- Activity 05: Which note matches?
- Activity 09: Plan Tony's exit
- Activity 10: Repair the Genesis copy
Sources & further reading
Companion notes for Coding Adventure by James Colby. Historical claims link to their sources; the examples are written for this learning trail.