← Curriculum track ← Learn hub
Quanta GenAI Curriculum · Python · Intermediate

Python Intermediate — 042: Calibrate stdlib wedges with fixture parametrization instincts centred on `Exceptions: catching, chaining, guarding` [512420]

Lesson 042: Exceptions: catching, chaining, guarding

Focus

This page is deliberate repetition with new literals: Intermediate drills Exceptions: catching, chaining, guarding; spin token 373765 makes this page unlike its neighbours.

Key ideas

Example (LESSON_UID = "intermediate-042")

# Intermediate drill L042 topic-4 micro-1 pattern-10
LESSON_UID = "intermediate-042"
spin_a, spin_b, spin_c = 287, 203, 458

def gate(v):
    if v < spin_a + 1:
        return "low", v ** 2
    if v > spin_b + 42:
        return "high", v // max(1, 1 + 1)
    return "mid", v + spin_c

cand = [3, 42, 146]
for candidate in cand:
    lbl, val = gate(candidate)
    print(candidate, lbl, val)

from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as scratch:
    target = Path(scratch) / "scratch-42.txt"
    snap = [55, 347, 639, 931]
    target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
    print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (458 + 131))

Practice

Practice 33: Shadow one variable purposely to spotlight scope quirks. Literal nudge 33.

Fingerprints