You are on page 1of 3

Debugging

Session Overview
This lecture starts with a brief explanation of why floating point numbers are only an approximation of the real numbers. Most of the lecture is about a systematic approach to debugging. Image courtesy of the Naval Surface Warfare Center, Dahlgren, VA.

Session Activities
Lecture Videos

Recitation 4: Recursion, Pseudo code and Debugging Lecture 7: Debugging (00:49:58)

About this Video Topics covered: Binary, float, floating point, approximations, debugging, runtime error. Resources

Lecture code handout (PDF) Lecture code (PY) Lecture slides (PDF)

Recitation Videos

(00:50:24)

About this Video Topics covered: Recursion, divide and conquer, base cases, iterative vs. recursive algorithms, Fibonacci numbers example, recursive bisection search, optional and default parameters, pseudo code, introduction to debugging, test cases and edge cases, and floating points.

Check Yourself
Why do computers use binary representations? answer It's easy to build hardware with two states, on and off.

Why shouldn't we test for equality with floats? answer Because computers use binary, floats are actually very close approximations of the actual values. Testing for equality can result in an unexpected error, so it's better to determine whether two numbers are close enough for our purposes rather than precisely equal.

When debugging, how can you ensure that the values in your program are the ones you think they are? answer Use print statements.

Problem Sets
Problem Set 3: Wordgames (Due) In this problem set, you'll implement two versions of the 6.00 wordgame! Don't be intimidated by the length of this problem set. It's a lot of reading, but it is very doable. Let's begin by describing the 6.00 wordgame: This game is a lot like Scrabble or Text Twist, if you've played those. Letters are dealt to players, who then construct one or more words out of their letters. Each valid word receives a score, based on the length of the word and the letters in that word.

Instructions (PDF) Code files (ZIP) (This ZIP file contains: 1 .txt file and 4 .py files.)

Solutions (ZIP) (This ZIP file contains: 2 .py files.)

Problem Set 4 (Assigned) Problem set 4 is assigned in this session. The instructions and solutions can be found on the session page where it is due, Lecture 10 Hashing and Classes.

Further Study
These optional resources are provided for students that wish to explore this topic more fully. Readings After watching the lecture, you may want to read some of the following resources:

8. Errors and Exceptions. Python Tutorial. Appendix A: Debugging. How to Think Like a Computer Scientist.

You might also like