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

Quiz 5

MCS 275 Spring 2021 - Emily Dumas

Instructions:

Deadline

This quiz must be submitted in Gradescope by 12:00pm CST on Tuesday, Februrary 15, 2021.

Topic

This quiz is about debugging Python programs and using pdb.

Resources you are allowed to consult

Quizzes are INDIVIDUAL, closed book, and only allow access to specified resources. For this quiz you can access:

Note that it is unusual for us to allow lecture slide access during quizzes, but this quiz does allow use of the slides from Lectures 10 and 11.

Point distribution

This quiz has 2 problems (numbered 2 and 3), each worth 4 points. The autograder for this quiz is different from other quizzes, and only assigns 2 points. Therefore, the final grading breakdown is:

Points Item
2 autograder
4 problem 2
4 problem 3
10 total

(No problem number 1, as usual)

The 2 points assigned by the autograder based on the presence of the required files will be recorded as problem 1 in Gradescope.

NOTE: You need to be able to take a screenshot

To complete this quiz, you'll need to be able to capture a screenshot of your computer to an image file that you can later upload as part of the assignment.

If you don't know how to do this, you can find instructions for all common operating systems at: https://www.take-a-screenshot.org/

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.