Debugging TRB CSI › Python Programming › Debugging

Debugging

Debugging என்பது ஒரு program-ல் இருக்கும் errors அல்லது bugs-ஐ கண்டுபிடித்து, analyze செய்து, correct செய்வது. Simple-a சொன்னால்: Program ஏன் சரியாக வேலை செய்யவில்லை என்பதை கண்டுபிடித்து சரிசெய்வதே debugging.

Free Advanced 10 min 56 cards 10 programs 7 MCQs v2
Definition
Meaning

Debugging என்பது ஒரு program-ல் இருக்கும் errors அல்லது bugs-ஐ கண்டுபிடித்து, analyze செய்து, correct செய்வது.

Program ஏன் சரியாக வேலை செய்யவில்லை என்பதை கண்டுபிடித்து சரிசெய்வதே debugging.

Simple Explanation
Core idea

நாம் program எழுதும்போது சில mistakes வரலாம்.

Program
Example
Python 3 lines
1x = 10
2y = 0
3print(x / y)
Explanation
Core idea

இங்கு program run செய்தால் error வரும்.

Reason

10 / 0 செய்ய முடியாது.

Detail 02

இந்த error எங்கு வந்தது, ஏன் வந்தது, எப்படி correct செய்வது என்பதை பார்க்கும் process தான் debugging.

Simple flow
  1. Program எழுதுகிறோம்
  2. Run செய்கிறோம்
  3. Error வருகிறது
  4. Error message படிக்கிறோம்
  5. Mistake கண்டுபிடிக்கிறோம்
  6. Code correct செய்கிறோம்
  7. Again run செய்கிறோம்
  8. Correct output கிடைக்கும்
Flow
  1. Write Program
  2. Run Program
  3. Observe Error / Wrong Output
  4. Identify Bug
  5. Find Cause
  6. Correct the Code
  7. Run Again
  8. Test Output
  9. Program Works Correctly
Explanation
Core idea

Debugging-க்கு தனியாக ஒரு single syntax கிடையாது.

Detail 01

Common debugging methods:

Syntax
Python 1 lines
1print(variable)
Syntax
அல்லது
Python 1 lines
1print("x =", x)
Program
Example
Python 2 lines
1x = 10
2y = 20
Program
Python 2 lines
1print("x =", x)
2print("y =", y)
Program
Python 1 lines
1result = x + y
Program
Python 1 lines
1print("result =", result)
Program
Program 1
Python 3 lines
1Program with Bug
2x = 10
3y = 0
Program
Python 1 lines
1print(x / y)
Verified output
ZeroDivisionError: division by zero
Learning Run Mode — this is the output the author verified, not a live execution.
Output
ZeroDivisionError: division by zero

இந்த output நமக்கு problem எது என்பதை காட்டுகிறது.

Line by Line
1
x = 10
x variable-க்கு 10 assign செய்கிறது.
2
y = 0
y variable-க்கு 0 assign செய்கிறது.
3
print(x / y)
Python: 10 / 0 calculate செய்ய முயற்சிக்கிறது. Zero-ஆல் divide செய்ய முடியாததால்: ZeroDivisionError வருகிறது. இதுதான் bug கண்டுபிடிக்க உதவும் error message.
Dry Run
Execution traceRead top to bottom · highlighted cells show the current value4 states
StepStatementxyResult
01Iteration 1x = 1010--
02Iteration 2y = 0100-
03Iteration 3x / y100Error
04Iteration 4Python stops100ZeroDivisionError
Comparison
Error vs Bug vs Debugging
PointErrorBugDebugging
MeaningProblem in programDefect causing problemProcess of fixing problem
ExampleSyntaxErrorWrong calculation logicFinding and correcting it
ResultProgram may failWrong behaviorCorrect program
ActionIdentifyLocateFix
Comparison
Testing vs Debugging
PointTestingDebugging
PurposeFind whether program worksFind why it fails
Main workCheck outputFind and fix bug
Done byTester / DeveloperMostly Developer
ResultError identifiedError corrected
Important
  1. Debugging means finding, analyzing and correcting bugs in a program.

  2. இந்த one line exam-க்கு முக்கியம்.

Common Mistake
Error 1
Context

Error message பார்க்காமல் code change செய்வது

Random-a code change செய்வது.

முதலில் error message படிக்க வேண்டும்.

Explanation
Example
NameError

name 'total' is not defined

இதில் Python clearly சொல்லுகிறது

total என்ற variable define செய்யப்படவில்லை.

Common Mistake
Error 2
Context

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)

Common Mistake
Error 3

Program run ஆகிறது என்றால் bug இல்லை என்று நினைப்பது

Program run ஆகலாம்.

ஆனால் wrong output கொடுக்கலாம்.

Program
Example
Python 2 lines
1length = 10
2breadth = 5
Program
Python 2 lines
1area = length + breadth
2print(area)
Verified output
15
Learning Run Mode — this is the output the author verified, not a live execution.
Output
15
Context

Program run ஆகிறது.

length × breadth

Program
Python 1 lines
1area = length * breadth
Verified output
50
Learning Run Mode — this is the output the author verified, not a live execution.
Output
50

இதுதான் logical bug.

Memory Trick

DEBUG

D
Detect problem
E
Examine error
B
Bug identify
U
Update code
G
Get correct output

Simple memory:

Debugging = Find Bug + Fix Bug

TRB Point
TRB Point 1

Debugging is the process of identifying and removing errors or bugs from a program.

TRB Point
TRB Point 2

A defect in a program is called a:

Bug

TRB Point
TRB Point 3

The process of correcting a bug is called:

Debugging

TRB Point
TRB Point 4
  1. Common Python errors include

    SyntaxError

  2. NameError

  3. TypeError

  4. ValueError

  5. ZeroDivisionError

  6. IndexError

  7. KeyError

TRB Point
TRB Point 5

Logical errors usually do not stop program execution, but they produce wrong output.

Interview Point
Question

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.

Interview Point
Question

What is a bug?

Answer

A bug is a defect or mistake in a program that causes incorrect behavior, wrong output or program failure.

Interview Point
Question

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.

MCQ
42What is debugging?
Choose one answer
MCQ
43A defect in a program is called:
Choose one answer
MCQ
44Which error occurs here? print(10 / 0)
Choose one answer
MCQ
45Which type of error may produce wrong output without stopping the program?
Choose one answer
MCQ
46What is the error? print(total) If total is not defined:
Choose one answer
MCQ
47Which tool can be used for simple debugging?
Choose one answer
MCQ
48What is the problem? x = 10 y = 20 print(x - y) If expected operation is addition:
Choose one answer
MCQ 8

Which one is a syntax error?

A.
x = 10
B.
print(x)

C.

if x > 5
    print(x)

D.

x = x + 1
Correct Answer

C

Explanation

The colon : after the if condition is missing.

Practice
Practice 1

Find the bug:

x = 10
y = 5

print(x + z)

Hint:

Which variable is not defined?

Answer:

z

Practice
Practice 2

Correct this program:

if 10 > 5
    print("Yes")

Correct version:

if 10 > 5:
    print("Yes")
Practice
Practice 3

Find the logical error:

length = 10
breadth = 5

area = length + breadth
print(area)

Correct:

area = length * breadth

Practice
Practice 4

Find the runtime error:

a = 100
b = 0

print(a / b)

Answer:

ZeroDivisionError

Practice
Practice 5

Use print() to debug:

x = 5
y = 10

result = x * y

print("x =", x)
print("y =", y)
print("result =", result)
Summary
  1. Bug என்பது program-ல் இருக்கும்defect அல்லது mistake.
  2. Debugging என்பது அந்த bug-ஐகண்டுபிடித்து சரிசெய்வது.
  3. Error message debugging-க்குமிகவும் useful.
  4. print() simple debugging method.
  5. Syntax Error code structureproblem.
  6. Runtime Error program run ஆகும்போது வரும்.
  7. Logical Error program run ஆகும்ஆனால் wrong output கொடுக்கும்.
  8. Debugging correct output பெறஉதவுகிறது.
Quick Revision
  1. Bug → Program mistake
  2. Debugging → Find + Fix bug
  3. Syntax Error → Grammar mistake
  4. Runtime Error → Execution timeerror
  5. Logical Error → Wrong logic, wrongoutput
  6. print() → Simple debugging tool
  7. Error message → Problemகண்டுபிடிக்க clue
  8. Debugging goal → Correct program +correct output
Text size
17px
Theme
Contents
Print / PDF
Program