Which stage lies?
Most real code is a pipeline: data flows through step after step, and the symptom only shows at the end. To isolate the faulty stage, print the value between every stage and compare each checkpoint against what you expected there. The first checkpoint that looks wrong points at the stage right before it, and everything downstream is innocent.
Two practical touches:
- print with
repr()(or an f-string's{x!r}) so hidden characters show up:'hello 'with a trailing space is invisible without the quotes - label every checkpoint (
after parse:), because five unlabeled lists teach you nothing
This is the experiment step of lesson 7-1's loop, run on all stages at once.
Code exercise · python
Run this healthy pipeline with labeled repr checkpoints. Note how each line lets you verify one stage independently of the rest.
Quiz
A four-stage pipeline prints checkpoints. Stages 1 and 2 look correct, stage 3's checkpoint is wrong, stage 4's is also wrong. Where is the bug?
Code exercise · python
Your turn. This pricing pipeline should print the healthy checkpoints shown in the expected output, but one stage has a bug. Run it, find the first wrong checkpoint, fix that stage only. A 10 percent discount on 10.00 should give 9.0.