A document from MCS 275 Spring 2021, instructor David Dumas. You can also get the notebook file.

Quiz 5 Solutions

MCS 275 Spring 2021 - David Dumas

Problem 2: Running puzzle.py in pdb

Demonstrate that you are able to run programs in pdb as follows:

Download this Python program:

When this program is run, it does some things and then exits with an exception. It produces no output.

Open a terminal (directly, not inside VS code). Open the program puzzle.py in the Python debugger pdb and use the continue command to start it running. It should raise an exception and enter pdb's post mortem debugging system.

With that post mortem debugging session visible in your terminal window, take a screenshot that either includes the entire screen, or which at least includes the entire terminal window and a small amount of space around it (>5 pixels on all sides).

The resulting screenshot should be an image file (with the extension jpg, png, or bmp). Include that screenshot file as part of your quiz submission to Gradescope.

Problem 3: Analyzing puzzle.py behavior

Use any method you like (pdb, print debugging, pencil + paper, ...) to find answers to these two questions:

  • A. On what line of puzzle.py is the exception raised that ends the program?
  • B. When the exception is raised, what is the value of the local variable x?

Now, create a text file quiz5prob3.txt using VS code and type the answer to each of the questions above, along with a short explanation of how you found it. Put each answer on a new line.

Include quiz5prob3.txt as part of your quiz submission to Gradescope.

To be completely clear about the format of this file, here is an example of what it should look like. This example uses a different set of questions than the ones given above, of course.

A. 365  I counted the number of boxes in a 2021 calendar on my wall.

B. 32  I started with 1 and doubled it 5 times.

A. 31 Because the traceback from running puzzle.py in pdb showed that the Exception was on line 31.

B. 378428 I added a print statement to display the value of x immediately before hitting the Exception in line 31.