Python Debugging
Debugging in any programming language typically involves two types of errors: syntax or logical. Syntax errors are those where the programming language commands are not interpreted by the compiler or interpreter because of a problem with how the program is written. These types of errors cause the program to either stop at the offending code or give a warning or error when the program execution is attempted. Once all of the syntax errors are discovered and corrected, logical errors still allow the program to run to completion but give incorrect results. Logical errors can be corrected by testing multiple conditions to check the correct operations or output of the program. Debugging in Python can either involve print statements or a more sophisticated debugger interface such as Spyder or ipdb.
Generative AI Learning
Debugging is the skill that makes AI-generated code safe to use, because generated code fails in exactly the two ways this page names: loudly (syntax/runtime errors) and silently (logical errors). Use these prompts to train both.
Tip: Rubber-duck the AI: before asking it to fix anything, explain your bug to it line by line as if it knows nothing - state what each line should do and what you observe instead. Most bugs die during the explanation. When you do paste a traceback, ask for the diagnosis and the reasoning, not just a patched file: you are training yourself, and an AI fix you cannot explain is a bug you will re-create next week.
What to Turn In
Submit a short report (PDF, 1-2 pages) that curates your results into a demonstration of what you learned. You may use Generative AI to help write the report, but the debugging must be demonstrably yours. Answer these questions:
- Keep a bug journal for this class's work: for three real bugs you hit (yours or planted), record the symptom, the traceback's bottom line in your own words, the root cause, and the fix.
- From the three-planted-bugs hunt: report each bug, its category (loud / silent / input-dependent), how you found it, and the test that proves your fix - did you find all three before asking for the reveal?
- Show one example of the rubber-duck technique: the explanation you wrote and the moment (which line) where the bug became obvious.
- From the quiz prompt: one question you missed and the corrected answer.
