Problem Statement
How do you debug a failing function using pdb? Mention key commands.
Explanation
Insert a breakpoint where state looks suspicious and run the program. Use step to go into functions, next to move over lines, and continue to resume until the next breakpoint. Print variables with p, and inspect the call stack with where.
This interactive loop lets you confirm assumptions and isolate the exact line that changes program state. Once you see the wrong value or branch, you can fix the cause rather than the symptom.
Code Solution
SolutionRead Only
import pdb pdb.set_trace() result = compute(x) # commands: n, s, c, p var, w
