Debugger
Learning Objective: Understand how to overcome a variety of errors by using the Debugger in the Python IDLE
There are three types of errors that you will come across:
Syntax Errors are a type of bug that comes from typos in your program. When the Python interpreter sees a syntax error, it is because your code is not written in proper Python language. A Python program with even a single syntax error will not run.
Runtime Errors are bugs that happen while the program is running (that is, executing). The program will work up until it reaches the line of code with the error, and then the program terminates with an error message (this is called crashing). The Python interpreter will display something called a "traceback" and show the line where the problem happens.
Semantic Errors are the trickiest bugs to fix. This bug does not crash the program, and the program may appear to work fine. However, it is not doing what the programmer intended for the program to do. For example, if the programmer wants the variable total to be the sum of the values in variables a, b, and c but writes total = a + b * c, then the value in total will be wrong. This won't cause the program to crash immediately, but may or may not cause some other code to crash later on because of the unexpected value in total
These are the 5 features of the Debugger:
- Go - Executes the rest of the code as normal, or until it reaches a break point. (Break points are described later.)
- Step - Step one line of code. If the line is a function call, the debugger will step into the function.
- Over - Step one line of code. If the line is a function call, the debugger will not step into the function, but instead step over the call.
- Out - Keeps stepping over lines of code until the debugger leaves the function it was in when Out was clicked. This steps out of the function.
- Quit - Immediately terminates the program.
TASKS:
- Copy and Paste the code from here: http://inventwithpython.com/dragon.py into the IDLE
- Open this and read about the IDLE's debugger http://inventwithpython.com/chapter7.html