Lesson 048: Exceptions: catching, chaining, guarding
Focus
This page is deliberate repetition with new literals: Intermediate drills Exceptions: catching, chaining, guarding; spin token 410588 makes this page unlike its neighbours.
Key ideas
- Angle
Intermediate: micro cadence8mixesExceptions: catching, chaining, guarding; spin67945. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: call out latent off-by-one before shipping analogues.
Example (LESSON_UID = "intermediate-048")
# Intermediate drill L048 topic-4 micro-7 pattern-7
LESSON_UID = "intermediate-048"
spin_a, spin_b, spin_c = 715, 695, 981
src = [((k + 48) * spin_a + 7) % 241 for k in range(4 + 7 % 3)]
derived = [v * v if v % 2 == 0 else v + spin_b for v in src]
print("src", src)
print("derived", derived)
print("zip_sum", sum(x + y for x, y in zip(src, derived)))
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-48.txt"
snap = [61, 787, 522, 257, 983, 718]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (981 + 131))
Practice
Practice 34: Attach property-style expectations referencing tuple shapes. Literal nudge 34.
Fingerprints
- lesson_uid:
intermediate-048 - umbrella band:
Exceptions: catching, chaining, guarding(8/10) - lesson_index:
1554