liveBook · Manning

Debugger

As explained in Learn AI-Assisted Python Programming, Second Edition

A debugger is a software tool that allows a programmer to inspect and control a program during execution to diagnose defects.

A debugger lets you inspect a program while it runs, helping you find bugs and understand how execution changes variable state. It complements print statements and can reveal why code produces an unexpected result. section 8.0 section 8.9

A practical debugging workflow is:

  • Run the failing test or example and reduce the investigation to the smallest useful case. section 8.5
  • Form a hypothesis about which update or condition is wrong, then place a breakpoint near it. section 8.5
  • Use Continue and Step Over while watching variables and the current input; confirm or reject the hypothesis. section 8.5
  • Correct the code, rerun the test, and restore any tests temporarily set aside. section 8.9

Counting consecutive students

A function is expected to return 4 for a row containing four consecutive students, but its doctest returns 3. Stepping through the loop shows that count reaches 4 only at the final seat; the code updates max_count only when an empty seat is encountered, so the final run is never recorded. Moving the update inside the student branch fixes the function. section 8.5

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Explains breakpoints, hypotheses, stepping, and variable inspection through a worked example, without low-level implementation details.
Examples
Demonstrates a failing doctest for counting consecutive students and traces count and max_count through a classroom grid.
What it assumes
Assumes small runnable programs and tests, while teaching execution tracing and variable-state inspection through simple examples.
What you can do after
Diagnose/debug with the VS Code debugger by setting breakpoints, stepping through execution, inspecting variables, and testing fixes.
How it connects
Connects debugging with unit testing, doctest, print statements, Visual Studio Code, and program execution.

Also explained in

Compare how 6 books explain debugger →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.