if when we run the instrumented program we find that the arguments are correct but that the return value is in errorwe know that we have located the source of the bug and can further investigate the function if looking carefully at the function doesn' suggest where the problem lieswe can simply insert new print(locals()"\ "statement right in the middle after running the program again we should now know whether the problem arises in the first or second half of the functionand can put print(locals()"\ "statement in the middle of the relevant halfrepeating the process until we find the statement where the error is caused this will very quickly get us to the point where the problem occurs--and in most cases locating the problem is half of the work needed to solve it the alternative to adding print(statements is to use debugger python has two standard debuggers one is supplied as module (pdb)and can be used interactively in the console--for examplepython - pdb my_program py (on windowsof coursewe would replace python with something like :\python \python exe howeverthe easiest way to use it is to add import pdb in the program itselfand add the statement pdb set_trace(as the first statement of the function we want to examine when the program is runpdb stops it immediately after the pdb set_trace(calland allows us to step through the programset breakpointsand examine variables here is an example run of program that has been instrumented by having the import pdb statement added to its importsand by having pdb set_trace(added as the first statement inside its calculate_median(function (what we have typed is shown in boldalthough where we typed enter is not indicated python statistics py sum dat statistics py( )calculate_median(-numbers sorted(numbers(pdbs statistics py( )calculate_median(-middle len(numbers/ (pdbstatistics py( )calculate_median(-median numbers[middle(pdbstatistics py( )calculate_median(-if len(numbers = (pdbstatistics py( )calculate_median(-return median (pdbp middlemediannumbers ( [- - ](pdbc