Exercise 8: HELP ME

This week we'll be doing something a bit different - rather than writing your own code, you'll be helping to debug (fix) my code!

  • bugs.txt - a text file containing at least 8 lines from the provided code file and descriptions of the errors present in them, as well as a 1-2 sentence description of what the program does (header comment). This part may be completed in pairs if you wish.
  • Lists & Dictionaries practice - on Learn@UW. This part should be completed individually.
  • Review questions - this part will not be graded, but we will be talking about them in class on 3/30 and they will help you prepare for the exam, so you may want to work through them.

Lists and dictionaries "Quiz"

This week we'll have a brief problem set (only 3 questions this time) with some problems using lists and dictionaries. It's available under Quizzes on Learn@UW.

You will have two attempts on this quiz — I recommend trying the first time with paper and pencil. You are welcome to use the interpreter and LiClipse to check your work on the second attempt.

Code Background

My code doesn't work. Help me fix it.

I want to use dictionaries for translating sentences into a number code (each letter becomes the corresponding number: a=1, b=2, etc.) and back. Case (upper vs lower) shouldn't matter.

There are at least 10 lines with one or more errors on them; some are syntax errors, some are logic errors. Find at least 8 errors, describe the error and how you might fix it.

The code file

Here's a link.


In order to help me fix my code effectively, your bugs.txt file should contain lines like this, pointing out the code line which contains the error, what the error is, and how to fix it:

Line 1: print hello world
Bug: Right now Python thinks hello and world are variables. Add quotes to make it a string.
Fix: print 'hello world'

Line 4: x += 5
Bug: NameError, x was never initialized.
Fix: add x = 0 somewhere before line 4

You should have at least 8 of these, but there are definitely more than 8 bugs in this code!

Submitting your files

As usual, you'll be handing in your lab work via the course Learn@UW dropboxes. Navigate to our 301 course page, and click the Dropbox link in the top navigation bar. You should see a dropbox for Program 8 - this is where you should hand in your bugs.txt file.

If you worked in a pair, only one person will need to hand in the text file.

Note that the dropbox will close at noon on 31 March, so be sure to submit your files before then.

Midterm Review Questions

This part of the assignment is ungraded, but we'll be talking about the questions in class on 30 March. I recommend working through the problems on your own first, but you may collaborate with as many people as you want (since this part is just for you and doesn't count toward your grade).


This is not intended to be similar to the length of a full exam, but questions are of comparable difficulty to the questions you will encounter on the exam.