4 Debugging9
4 Debugging9
4 Debugging9
Syllabus
2021-22
Chapter 9
Error Handling
Computer Science
Class XI ( As per CBSE Board)
Execution/Running a program
In python IDLE program is executed from run module option of run menu
Debugging
Create a.py file with below code and run it in python use n to step
next line.
num_list = [500, 600, 700]
alpha_list = ['x', 'y', 'z']
import pdb
pdb.set_trace() #debugging code
def nested_loop():
for number in num_list:
print(number)
for letter in alpha_list:
print(letter)
Debugger tool
Another technique for removing an error is code tracing. In this
technique, lines are to be executed one by one and their effect on
variables is to be observed. Debugging tool or debugger tool is
provided in Python for this.
In Python3.6.5, to make debugger tool available, click on debugger
option in debug menu.
Debugging
Debugger tool
Then, a box will be opened and a message will come saying DEBUG
ON
Then, we will open our program from file menu and will run it.
Debugging
Debugger tool
Then after it will be shown like this in debugger.
Click on STEP button for each line execution one by one and result
will be displayed in output window. When we will get wrong
value, we can stop the program there and can correct the code.