promptdojo_
chapter 01

read the script

ai hands you code before you feel ready to read it. this lab covers the three reads that matter first: what the names hold, whether the function actually returns, and which branch of the if-chain really fires.

3 live lessons · 24 live steps · 78 XP

Why a code-reading lab

You are not here to become a Python programmer. You are here because AI tools will hand you small scripts, formulas, workflows, and snippets all year — and if you cannot read the first five lines, you cannot stay in charge of the tool you asked for.

So this chapter is a lab, not a course. PromptDojo is not a syntax school. The goal is: when AI gives you a tiny program, you can run it, point at the important names, say whether the function actually hands its answer back, and tell which branch of an if chain really fires. Those three reads catch most of what AI gets wrong in small scripts.

The tiny mental model

A program needs names for things.

limit = 10
used = 7
remaining = limit - used

Read that like a note, not like math class:

  • limit is the number the tool is allowed to use
  • used is what already happened
  • remaining is the answer after subtracting one from the other

That is enough to begin. Everything else in this lab builds on reading lines like these and asking: what value does this name point to right now, and where does it go next?

What this lab covers in three lessons

Lesson 1: Names and values. The names a script uses, the few shapes values come in (number, text, flag, None), and the one idea that trips up every non-coder exactly once: = doesn't mean what it did in math class. It's a command, not a claim.

Lesson 2: Functions and the hallucinated return. AI writes functions constantly, and the silently missing return is one of its best-documented failure modes. The function does the work, computes the answer — and never hands it back. The caller gets None and your code fails three steps later. You'll learn to spot it on sight, and to tell return from print, which AI mixes up when you ask it to "show the result."

Lesson 3: Decisions — if/elif chains. if looks simple. The traps inside it — 0 and empty values counting as false, == versus is, branches ordered so the right one can never fire — are where AI quietly ships wrong code. You'll fix each of those bugs by hand.

Where AI specifically gets this wrong

The bug list this lab trains you to catch:

  • Name typos. A variable defined as total and used as totlNameError, and the fix is one careful read.
  • The hallucinated return. The flagship bug. The function computes the answer and drops it on the floor; the caller gets None.
  • print where return belongs. The value is visible on screen but not captured — nothing downstream can use it.
  • Truthy traps. if score: treats a real score of 0 the same as "no score at all." if items: can't tell an empty list from a missing one.
  • == vs is. Both "work" in a quick demo; only one keeps working when the value arrives from a file or an API. The rule: use == for everything, use is only for None.
  • Branch order. An if score >= 70 placed above elif score >= 90 means "excellent" can never fire. No crash, no warning — just silently wrong output.

What you'll be able to do at the end

Three lessons, 24 steps. By the end you will be able to:

  • run a tiny AI-generated script and explain where each part of the output came from
  • read a function definition and predict what calling it returns — including when the answer is None
  • spot the missing-return bug in thirty seconds of code review
  • predict whether an if condition fires on a given value, including the zero/empty/None edge cases
  • fix the wrong-order elif chain that ships silently wrong results
  • use your own AI assistant as a syntax reference, with the verification habit that keeps it honest

Every later chapter assumes these three reads. Get them in your hands here and the rest of the curriculum reads like review.

Press Start chapter below.