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
- Lecture 7: Debugging (00:49:58)
About this Video
Topics covered: Binary, float, floating point, approximations, debugging, runtime error.
Resources
Recitation Videos
-
Recitation 4: Recursion, Pseudo code and Debugging (00:50:24)
Recitation 4: Recursion, Pseudo code and Debugging
> Download from iTunes U (MP4 - 109MB)
> Download from Internet Archive (MP4 - 109MB)
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?
› View/hide answer
It's easy to build hardware with two states, on and off.
Why shouldn't we test for equality with floats?
› View/hide 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?
› View/hide 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.