🐍 Python for Everyone

← Back to the project

Chapter 33 (Final Chapter) — Solo → AI-Paired → Critique 30 min

Now Pair With an AI

Step 1: You already built this solo

You just built careerprep yourself, unaided — a packaged CLI tool with a real question bank, an answers file that appends across sessions, and a checklist scanner that actually reads files on disk. That project is unchanged; this page is additive. Now imagine the more common real-world move: you already have a working v1, and you ask an AI assistant to bolt on three specific improvements in one pass — the way developers actually reach for an assistant once the skeleton exists and they just want the next features done fast.

Step 2: Now pair with an AI

Here's a real prompt a learner could give an AI assistant, extending the working careerprep from Step 1 instead of starting over:

the-prompt.txt
I have a working CLI tool called careerprep with a question bank,
a JSON answers file, and a portfolio checklist scanner. Add three
things: (1) in the checklist scanner, a _check_readme(target) helper
that checks whether the project has a real README.md; (2) a
record_answer(answers_file, question, answer_text) function that
saves a learner's typed answer to the JSON file; (3) a
pick_unseen_question(answers_file, category=None) function for a new
--avoid-repeats mode that picks a random question the learner
HASN'T already answered, based on their saved answer history. Please
just give me the working code for all three.

And here's a plausible response — the kind of complete, confident-looking output an AI assistant might hand back on the first try. Read it the way you'd review a pull request from a teammate who moved fast, before scrolling to the critique below.

careerprep/checklist.py (AI output)
def _check_readme(target: Path) -> bool:
    """Check whether the project has a real README."""
    return (target / "README.md").exists()
careerprep/interview.py (AI output)
def record_answer(answers_file: Path, question: dict, answer_text: str) -> dict:
    """Save the learner's answer to the answers file."""
    entry = {
        "question_id": question["id"],
        "category": question["category"],
        "question_text": question["text"],
        "answer": answer_text.strip(),
        "answered_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
    }

    answers_file.parent.mkdir(parents=True, exist_ok=True)
    answers_file.write_text(json.dumps([entry], indent=2), encoding="utf-8")
    logger.info("Saved answer for question #%d", question["id"])
    return entry


def pick_unseen_question(answers_file: Path, category: str | None = None) -> dict:
    """Pick a random question the learner hasn't answered yet, for --avoid-repeats mode."""
    answered_ids = {a["question_id"] for a in load_answers(answers_file)}
    questions = get_questions(category)
    unseen = [q for q in questions if q["id"] not in answered_ids]

    if not unseen:
        print("You've answered every question in this category! Picking a random one anyway.")

    return random.choice(questions)

It's complete, it imports cleanly, and it looks like exactly the kind of fast, thorough answer you asked for — a README existence check, an answer saver with a real timestamp, and an "avoid repeats" picker that visibly computes an unseen list and even handles the "you've answered everything" edge case with a friendly message. It's also wrong in three separate, genuinely subtle ways.

Step 3: Where did the AI's code lie to you?

Click to see the critique

What it looks like it does: "check whether the project has a real README.md" reads like it's checking for something meaningful — the word "real" is right there in the docstring.

What it actually does: confirmed by actually running it — a directory containing a README.md whose entire content is the single word TODO returns True. Path.exists() only asks "is there a file at this path," it has no opinion at all about what's inside it. A learner scanning their own capstone folder with this version would see a passing checkmark next to "README" even if they'd forgotten to actually write one.

Why it matters: this is the exact shortcut this chapter's own scan_directory deliberately avoids — it checks both that a README file exists and that its stripped content clears a minimum length (200 characters), specifically so a one-line placeholder doesn't quietly pass as "done." A checklist tool that can't tell the difference between "wrote a README" and "created an empty file named README.md" isn't measuring the thing it claims to measure.

The fix: read the file's content, strip it, and compare its length against a real threshold — see this chapter's own _is_substantial() helper in solution/careerprep/checklist.py for the working version.

What it looks like it does: it builds a real entry dict with a real timestamp, creates the parent folder, writes JSON, and logs an info message — every individual line looks correct in isolation.

What it actually does: json.dumps([entry], indent=2) wraps only the new entry in a list and writes that — it never calls load_answers() first to get the existing history. Confirmed by actually running it twice in a row with two different questions: after the second call, the file contains exactly one entry (the second one), not two. The first practice session's answer is gone, with no error, no warning, and a log line that says "Saved answer" as if everything worked.

Why it matters: the entire point of a mock-interview drill tool is watching your answers to the same question improve across multiple sessions — that's explicitly what this chapter's interview review command is for. A version that overwrites on every save can never show more than the single most recent answer, silently destroying the exact history the tool exists to build. This is a worse failure than a crash: it looks like it's working, prints a success message, and the data loss is invisible until a learner runs review weeks later and finds only one saved answer where there should be a dozen.

The fix: load the existing answers first, append the new entry to that list, and save the whole list back — answers = load_answers(answers_file); answers.append(entry); save_answers(answers_file, answers). See this chapter's own record_answer() in solution/careerprep/interview.py for the working version.

What it looks like it does: it builds answered_ids from the saved history, filters questions down to unseen, and even prints a considerate message for the "you've answered everything" edge case — every piece of the filtering logic is visibly present and looks deliberate.

What it actually does: the final line is return random.choice(questions) — the full, unfiltered list — not random.choice(unseen). The unseen variable is computed, checked for emptiness, and then never used again. Confirmed by actually running it: seeded with 4 already-answered questions out of 5 total, 30 calls to pick_unseen_question returned an already-answered question 24 out of 30 times — almost exactly what you'd expect from picking uniformly at random from all 5 questions, meaning the "avoid repeats" filtering had zero effect on the actual output.

Why it matters: this is the most dangerous kind of bug to catch by reading alone — the code that computes the right answer is right there, so a quick skim sees "yes, it filters by answered_ids" and moves on. It only surfaces by actually running it and checking whether repeats really stop happening, which is exactly why "confirmed by actually running it" matters more than "the logic looks right" throughout this whole course.

The fix: change the return statement to random.choice(unseen) when unseen is non-empty, falling back to random.choice(questions) only in the genuine "answered everything" case the code already detects and prints a message for.

Step 4: Your entry for this chapter's playbook

This is the last chapter of the course, so this entry is a fitting capstone to a thread that's run through every single project's ai-paired.html: an AI assistant's code almost always looks complete — it imports cleanly, it has docstrings, it handles the edge case you'd expect it to miss. The skill this course has been building, one chapter at a time, isn't "write a prompt" — it's noticing the gap between what a block of code claims to do and what it actually does when you run it, especially when the claim is confident and the gap is one line wide (a wrong variable in a return statement, a missing load_answers() call, a check that measures existence instead of quality). Fill this in for yourself — it's not saved or sent anywhere, just yours to keep.

← Back to the Project All Chapters →