AI-written code that looks right but is not
Find the two problems before you read the output: one in the even-length case, one in what the function does to its input.
AI coding assistants such as Copilot, Cursor, Claude Code and Codex write plausible Python quickly, and plausible is not the same as correct. Give them context, ask for tests, review what they produce, and verify with tests, type checks and Ruff before you trust it.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write find_bare_excepts(source) that returns the line numbers of bare except: clauses using ast.
Write slugify(title) and a function check_slugify() whose assertions cover normal, extra-space, empty and upper-case input.
Write first_word(text) that returns the first word, or an empty string for empty or blank text.
Explain it without notes
How do you give an AI assistant enough context to produce useful Python?
Name typical mistakes in AI-written Python and a way to catch each.
Why is it risky to accept AI-written code without tests?
A teammate opens a 600-line pull request that was mostly written by an AI assistant. How do you review it?
Expected output
PASS odd length: got 2, expected 2
FAIL even length: got 3, expected 2.5
PASS single value: got 7, expected 7
caller's list after the call: [1, 4, 5]