Hands-on Python with Claude Code · Challenge 03 · 中文版

Lesson 3: Drive a bounded change, test by test

Checkpoint l0310 ptsgated by test suiteClaude Code 2.x

Let the agent edit the starter under contract — smallest change, no new dependencies, red to green one group at a time.

Doing this with your agent? One sentence starts the whole course:

Read https://flypython.com/skills/flypython/SKILL.md and start the FlyPython course `hands-on-python-with-claude-code`.

Lesson 3: Drive a bounded change, test by test

Objective

The starter passes all nine tests through a sequence of bounded changes, and you can explain every diff the agent produced without reading the solution first.

Why this lesson exists

This is the lesson people skip — and the one that builds the actual skill. Watching an agent make seven failing tests pass in one giant rewrite teaches you nothing. Supervising seven small diffs, each pinned to a contract line, teaches you how to keep AI-written code yours.

The lesson

Tell the agent: “Work through TASK.md against starter/report_tool.py. One failing test group at a time: JSON loading, then validation isolation, then rounding, then atomic writes, then the end-to-end tests. After each group, run the suite and show me the diff before continuing.”

Hold it to the contract’s boundaries:

  • Only starter/report_tool.py changes. If a diff touches tests/, solution/, or scenario/, stop and ask why.
  • No new imports outside the standard library — and no import that is not needed by the change being made.
  • Each change should move toward one contract line. Reject drive-by refactors (“while I was here I renamed…”).
  • If the agent wants to change a test, the answer is no. Tests are the contract; the code moves.

Run the suite after each group:

PYTHONPATH=starter python -m unittest discover -s tests -v

Expect the failing count to drop group by group: 7 → 5 → 4 → 3 → 2 → 0.

Exercise

Do the last group yourself. When only the end-to-end tests remain, write the run_scenario/main fix by hand (they are small), then run the full suite. Reading the agent’s diff is learning; writing the last ten lines is internalizing.

Checkpoint

python verify.py starter --expect-failure   # must now FAIL the expectation: starter passes
python verify.py starter                    # must pass all nine tests

The first command failing is good news — it means the starter is no longer correctly unfinished. Then answer: which change was smallest? Which would you have over-built?

Expected evidence

Test transcript from 7 failures to 0, plus the diffs. You are allowed to open solution/ only after your starter passes — compare approaches, then note one thing the reviewed solution does that yours does not.

Hints

Stuck? Open one at a time.

Hint 1 — What this checkpoint tests

The gate is python verify.py starter — all nine tests green against your starter. Work one failing group at a time: load_records (csv/json/ValueError), then build_report, then write_report, then main.

Hint 2 — Traps the suite actually asserts

Booleans are not numbers — isinstance(True, int) is True, so exclude bools explicitly. Group totals round to two decimals. total = valid + invalid must hold even when every row is invalid.

Hint 3 — Atomic means atomic

write_report must use a sibling temp file plus os.replace, and no .tmp may survive a successful write — the suite checks the filesystem, not your intentions. Still red? Run the unittest directly to see the failing name.

Submit

Done? Record it.

The 8-character code verify.py progress printed for this checkpoint — from the browser, or straight from your agent.

Youbrowser

Submit the claim code

Your agentauto-submit

Let the agent solve and submit

Hand it this checkpoint (copy button on hover) — it solves, verifies, and submits on its own:

Work on the FlyPython challenge "Hands-on Python with Claude Code" (course id course-claude-code), checkpoint l03.
Machine-readable brief: https://flypython.com/api/challenges/hands-on-python-with-claude-code
Open the course folder and read TASK.md first — it is the contract.
Rules: smallest change, no new dependencies, never edit tests/ or solution/.
Check with python verify.py until its gates pass, then report each claim code to me.
Target: solve only checkpoint l03, and submit it as soon as it passes.

With a token from your agent page (env FLYPYTHON_TOKEN), it records the result directly:

curl -X POST https://flypython.com/api/claims \
  -H "Authorization: Bearer $FLYPYTHON_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"claims":[{"course":"hands-on-python-with-claude-code","checkpoint":"l03","code":"<8-char code>"}]}'

Or install the full FlyPython agent skill once and skip the paste.

Official demo · Pro

Watch how a human runs this challenge

An official walk-through of this exact checkpoint — the task-contract handoff, the moment the agent is stopped, the uncut failure correction, the verify.py gates. Included in Pro; there is no free preview, and the challenge itself stays free.

Files

The starter and verifier

Solving runs on your machine — your agent fetches the course files itself via /api/challenges/hands-on-python-with-claude-code/files; you download nothing by hand. Prefer reading the source? Browse the folder on GitHub ↗