Debugging என்பது ஒரு program-ல் இருக்கும் errors அல்லது bugs-ஐ கண்டுபிடித்து, analyze செய்து, correct செய்வது.
Program ஏன் சரியாக வேலை செய்யவில்லை என்பதை கண்டுபிடித்து சரிசெய்வதே debugging.
Debugging என்பது ஒரு program-ல் இருக்கும் errors அல்லது bugs-ஐ கண்டுபிடித்து, analyze செய்து, correct செய்வது. Simple-a சொன்னால்: Program ஏன் சரியாக வேலை செய்யவில்லை என்பதை கண்டுபிடித்து சரிசெய்வதே debugging.
Debugging என்பது ஒரு program-ல் இருக்கும் errors அல்லது bugs-ஐ கண்டுபிடித்து, analyze செய்து, correct செய்வது.
Program ஏன் சரியாக வேலை செய்யவில்லை என்பதை கண்டுபிடித்து சரிசெய்வதே debugging.
நாம் program எழுதும்போது சில mistakes வரலாம்.
1x = 10 2y = 0 3print(x / y)
இங்கு program run செய்தால் error வரும்.
10 / 0 செய்ய முடியாது.
இந்த error எங்கு வந்தது, ஏன் வந்தது, எப்படி correct செய்வது என்பதை பார்க்கும் process தான் debugging.
Debugging-க்கு தனியாக ஒரு single syntax கிடையாது.
Common debugging methods:
1print(variable)
1print("x =", x)
1x = 10 2y = 20
1print("x =", x) 2print("y =", y)
1result = x + y
1print("result =", result)
1Program with Bug 2x = 10 3y = 0
1print(x / y)
ZeroDivisionError: division by zero
ZeroDivisionError: division by zero
இந்த output நமக்கு problem எது என்பதை காட்டுகிறது.
| Step | Statement | x | y | Result |
|---|---|---|---|---|
| 01Iteration 1 | x = 10 | 10 | - | - |
| 02Iteration 2 | y = 0 | 10 | 0 | - |
| 03Iteration 3 | x / y | 10 | 0 | Error |
| 04Iteration 4 | Python stops | 10 | 0 | ZeroDivisionError |
| Point | Error | Bug | Debugging |
|---|---|---|---|
| Meaning | Problem in program | Defect causing problem | Process of fixing problem |
| Example | SyntaxError | Wrong calculation logic | Finding and correcting it |
| Result | Program may fail | Wrong behavior | Correct program |
| Action | Identify | Locate | Fix |
| Point | Testing | Debugging |
|---|---|---|
| Purpose | Find whether program works | Find why it fails |
| Main work | Check output | Find and fix bug |
| Done by | Tester / Developer | Mostly Developer |
| Result | Error identified | Error corrected |
Debugging means finding, analyzing and correcting bugs in a program.
இந்த one line exam-க்கு முக்கியம்.
Error message பார்க்காமல் code change செய்வது
Random-a code change செய்வது.
முதலில் error message படிக்க வேண்டும்.
name 'total' is not defined
total என்ற variable define செய்யப்படவில்லை.
Syntax Error மற்றும் Logical Error ஒன்றே என்று நினைப்பது
if x > 5
print(x)Colon : missing.
print(x)
x = 10 y = 20 print(x - y) நமக்கு addition வேண்டும் என்றால் code run ஆகும், ஆனால் wrong answer வரும்.
print(x + y)
Program run ஆகிறது என்றால் bug இல்லை என்று நினைப்பது
Program run ஆகலாம்.
ஆனால் wrong output கொடுக்கலாம்.
1length = 10 2breadth = 5
1area = length + breadth 2print(area)
15
15
Program run ஆகிறது.
length × breadth
1area = length * breadth
50
50
இதுதான் logical bug.
DEBUG
Simple memory:
Debugging = Find Bug + Fix Bug
Debugging is the process of identifying and removing errors or bugs from a program.
A defect in a program is called a:
Bug
The process of correcting a bug is called:
Debugging
SyntaxError
NameError
TypeError
ValueError
ZeroDivisionError
IndexError
KeyError
Logical errors usually do not stop program execution, but they produce wrong output.
What is debugging?
Answer
Debugging is the process of finding, analyzing and fixing errors or bugs in a program. It helps the programmer understand why the code fails or produces incorrect output.
What is a bug?
Answer
A bug is a defect or mistake in a program that causes incorrect behavior, wrong output or program failure.
What is the difference between testing and debugging?
Answer
Testing is used to identify whether a program has a problem. Debugging is used to locate the cause of that problem and fix it.
Which one is a syntax error?
C.
if x > 5
print(x)D.
x = x + 1
Correct Answer
C
Explanation
The colon : after the if condition is missing.
Find the bug:
x = 10 y = 5 print(x + z)
Hint:
Which variable is not defined?
Answer:
z
Correct this program:
if 10 > 5
print("Yes")Correct version:
if 10 > 5:
print("Yes") Find the logical error:
length = 10 breadth = 5 area = length + breadth print(area)
Correct:
area = length * breadth
Find the runtime error:
a = 100 b = 0 print(a / b)
Answer:
ZeroDivisionError
Use print() to debug:
x = 5
y = 10
result = x * y
print("x =", x)
print("y =", y)
print("result =", result)