Movatterモバイル変換


[0]ホーム

URL:


Uploaded bycpics
PPTX, PDF17 views

Introduction to Python_Debugging_Errors.pptx

python debug

Embed presentation

Download to read offline
Dealing with Syntax Errors,Runtime Errors, and ScientificDebuggingPython Programming - Lecture 4
Introduction to Errors in Python• - Errors are mistakes in code that prevent execution.• - Even experienced programmers make errors.• - Debugging is the process of identifying and fixingerrors.• 🔹 Types of Errors:• Syntax Errors – Code structure mistakes.1 ️1️⃣• Runtime Errors – Errors during execution.2️⃣• Logical Errors – Incorrect output without crashing.3 ️3️⃣
Syntax Errors in Python• ❌ Syntax errors occur when Python encountersincorrect code structure.• ✅ Fixing Syntax Errors:• - Check for missing colons, parentheses, orincorrect indentation.• - Use an IDE with syntax highlighting.
Example of Syntax Errors• 🔴 Missing Colon (:) in If Statement:• ```• age = 18• if age >= 18 # SyntaxError: Missing colon• print("You are an adult")• ```• 🔴 Unmatched Parentheses:• ```• print("Hello World # SyntaxError: Missing closing quote• ```
Runtime Errors in Python• ⚠️Runtime errors occur **during programexecution**.• ✅ Fixing Runtime Errors:• - Always check for invalid operations (e.g.,division by zero).• - Ensure variables are defined before use.
Example of Runtime Errors• 🔴 Division by Zero:• ```• num = 5• print(num / 0) # ZeroDivisionError• ```• ✅ Fix:• ```• if num != 0:• print(num / 2)• else:• print("Cannot divide by zero")• ```
Logical Errors in Python• 🔸 Logical errors do not crash the program, butthey produce incorrect output.• ✅ How to Identify Logical Errors:• - Use `print()` statements to track variablevalues.• - Debug with small test cases before runninglarge programs.
Example of Logical Errors• 🔴 Incorrect Formula for Average Calculation:• ```• a, b, c = 10, 20, 30• average = a + b + c / 3 # Wrong formula• print("Average:", average)• ```• ✅ Correct Formula:• ```• average = (a + b + c) / 3• print("Average:", average)• ```
Debugging Techniques in Python• ✅ Common Debugging Methods:• 1. Using `print()` statements.• 2. Using Python's built-in debugger (`pdb`).• 3. Using an IDE with debugging tools.
Example of Debugging with print()• ```• x = 10• print("Value of x:", x) # Debugging usingprint()• ```
Example of Debugging with pdb• ```• import pdb• def add(a, b):• pdb.set_trace() # Debugging starts here• return a + b• result = add(5, 10)• print("Result:", result)• ```
Summary and Key Takeaways• - **Syntax errors**: Code structure mistakes,easily fixed.• - **Runtime errors**: Happen duringexecution (e.g., division by zero).• - **Logical errors**: Cause incorrect resultswithout crashing.• - Debugging techniques: `print()`, `pdb`, andusing an IDE for error detection.
Activity - Fix the Errors• ❓ Identify and fix the errors in the followingcode:• ```• num = input("Enter a number: ")• print("The square is: " + num * num)• ```• ✅ Hint: Fix data type errors.

Recommended

PPTX
Python Exception Handling
PDF
(1.4) Identifying and Correcting Errors - PDF.pdf
PPTX
Exception Handling and Modules in Python.pptx
PPTX
EXCEPTION HANDLING class 12th computer science.pptx
PPT
Exception handling and function in python
PDF
Python programming : Exceptions
PPTX
Programming Error or Bug.pptx
 
PPTX
Python Unit II.pptx
PPTX
LECT 29- EXCEPTION HANDLING.pptx b.
PDF
GE3151_PSPP_UNIT_5_Notes
PPTX
Python.pptx
PPTX
Types of Handling functions in Python with an example
PDF
Python progr Module 1 final- 1BPLCK105B-2025.pdf
PDF
Introduction to Python - Algorithm Compiler
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PPTX
Download Wondershare Filmora Crack Latest 2025
PPTX
FL Studio Producer Edition Crack 24 + Latest Version [2025]
PPTX
Exception Handling in python programming.pptx
PDF
Exception handling in python
PPTX
Chapter-12 Error and exception handling.pptx
PPTX
Exception Handling in Python
PPTX
Adobe Photoshop 2025 Cracked Latest Version
PDF
Python Puzzlers
PDF
Python From Scratch (1).pdf
PPTX
Python Lecture 7
PPTX
Introduction to Python Basics
PDF
AI Workflows and Workflow Rhetoric - by Ms. Oceana Wong
PDF
Digital Journalism Ethics 2025 materi for Regulation & Ethic Media

More Related Content

PPTX
Python Exception Handling
PDF
(1.4) Identifying and Correcting Errors - PDF.pdf
PPTX
Exception Handling and Modules in Python.pptx
PPTX
EXCEPTION HANDLING class 12th computer science.pptx
PPT
Exception handling and function in python
PDF
Python programming : Exceptions
PPTX
Programming Error or Bug.pptx
 
Python Exception Handling
(1.4) Identifying and Correcting Errors - PDF.pdf
Exception Handling and Modules in Python.pptx
EXCEPTION HANDLING class 12th computer science.pptx
Exception handling and function in python
Python programming : Exceptions
Programming Error or Bug.pptx
 

Similar to Introduction to Python_Debugging_Errors.pptx

PPTX
Python Unit II.pptx
PPTX
LECT 29- EXCEPTION HANDLING.pptx b.
PDF
GE3151_PSPP_UNIT_5_Notes
PPTX
Python.pptx
PPTX
Types of Handling functions in Python with an example
PDF
Python progr Module 1 final- 1BPLCK105B-2025.pdf
PDF
Introduction to Python - Algorithm Compiler
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PPTX
Download Wondershare Filmora Crack Latest 2025
PPTX
FL Studio Producer Edition Crack 24 + Latest Version [2025]
PPTX
Exception Handling in python programming.pptx
PDF
Exception handling in python
PPTX
Chapter-12 Error and exception handling.pptx
PPTX
Exception Handling in Python
PPTX
Adobe Photoshop 2025 Cracked Latest Version
PDF
Python Puzzlers
PDF
Python From Scratch (1).pdf
PPTX
Python Lecture 7
PPTX
Introduction to Python Basics
Python Unit II.pptx
LECT 29- EXCEPTION HANDLING.pptx b.
GE3151_PSPP_UNIT_5_Notes
Python.pptx
Types of Handling functions in Python with an example
Python progr Module 1 final- 1BPLCK105B-2025.pdf
Introduction to Python - Algorithm Compiler
lecs101.pdfgggggggggggggggggggddddddddddddb
Download Wondershare Filmora Crack Latest 2025
FL Studio Producer Edition Crack 24 + Latest Version [2025]
Exception Handling in python programming.pptx
Exception handling in python
Chapter-12 Error and exception handling.pptx
Exception Handling in Python
Adobe Photoshop 2025 Cracked Latest Version
Python Puzzlers
Python From Scratch (1).pdf
Python Lecture 7
Introduction to Python Basics

Recently uploaded

PDF
AI Workflows and Workflow Rhetoric - by Ms. Oceana Wong
PDF
Digital Journalism Ethics 2025 materi for Regulation & Ethic Media
PDF
বাংলাদেশ অর্থনৈতিক সমীক্ষা - ২০২৫ with Bookmark.pdf
PDF
The invasion of Alexander of Macedonia in India
PDF
Deep Research and Analysis - by Ms. Oceana Wong
PDF
AI Chatbots and Prompt Engineering - by Ms. Oceana Wong
PDF
AI and ICT for Teaching and Learning, Induction-cum-Training Programme, 5th 8...
PDF
Agentic AI and AI Agents 20251121.pdf - by Ms. Oceana Wong
PDF
ASRB NET 2025 Paper GENETICS AND PLANT BREEDING ARS, SMS & STODiscussion | Co...
PDF
CXC-AD Associate Degree Handbook (Revised)
PPTX
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...
PDF
*Unit-II A (Elements of Communication & Communication Style Matrix)
PPTX
LYMPHATIC SYSTEM.pptx it includes lymph, lymph nodes, bone marrow, spleen
PPTX
Physical education notes class ncert 12th
PPTX
Masterclass on Cybercrime, Scams & Safety Hacks.pptx
PPTX
DEPED MEMORANDUM 089, 2025 PMES guidelines pptx
PPTX
Declaration of Helsinki Basic principles in medical research ppt.pptx
PPTX
G-Protein-Coupled Receptors (GPCRs): Structure, Mechanism, and Functions
PPTX
SEMESTER 5 UNIT- 1 Difference of Children and adults.pptx
PPTX
Time Series Analysis - Weighted (Unequal) Moving Average Method
AI Workflows and Workflow Rhetoric - by Ms. Oceana Wong
Digital Journalism Ethics 2025 materi for Regulation & Ethic Media
বাংলাদেশ অর্থনৈতিক সমীক্ষা - ২০২৫ with Bookmark.pdf
The invasion of Alexander of Macedonia in India
Deep Research and Analysis - by Ms. Oceana Wong
AI Chatbots and Prompt Engineering - by Ms. Oceana Wong
AI and ICT for Teaching and Learning, Induction-cum-Training Programme, 5th 8...
Agentic AI and AI Agents 20251121.pdf - by Ms. Oceana Wong
ASRB NET 2025 Paper GENETICS AND PLANT BREEDING ARS, SMS & STODiscussion | Co...
CXC-AD Associate Degree Handbook (Revised)
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...
*Unit-II A (Elements of Communication & Communication Style Matrix)
LYMPHATIC SYSTEM.pptx it includes lymph, lymph nodes, bone marrow, spleen
Physical education notes class ncert 12th
Masterclass on Cybercrime, Scams & Safety Hacks.pptx
DEPED MEMORANDUM 089, 2025 PMES guidelines pptx
Declaration of Helsinki Basic principles in medical research ppt.pptx
G-Protein-Coupled Receptors (GPCRs): Structure, Mechanism, and Functions
SEMESTER 5 UNIT- 1 Difference of Children and adults.pptx
Time Series Analysis - Weighted (Unequal) Moving Average Method

Introduction to Python_Debugging_Errors.pptx

  • 1.
    Dealing with SyntaxErrors,Runtime Errors, and ScientificDebuggingPython Programming - Lecture 4
  • 2.
    Introduction to Errorsin Python• - Errors are mistakes in code that prevent execution.• - Even experienced programmers make errors.• - Debugging is the process of identifying and fixingerrors.• 🔹 Types of Errors:• Syntax Errors – Code structure mistakes.1 ️1️⃣• Runtime Errors – Errors during execution.2️⃣• Logical Errors – Incorrect output without crashing.3 ️3️⃣
  • 3.
    Syntax Errors inPython• ❌ Syntax errors occur when Python encountersincorrect code structure.• ✅ Fixing Syntax Errors:• - Check for missing colons, parentheses, orincorrect indentation.• - Use an IDE with syntax highlighting.
  • 4.
    Example of SyntaxErrors• 🔴 Missing Colon (:) in If Statement:• ```• age = 18• if age >= 18 # SyntaxError: Missing colon• print("You are an adult")• ```• 🔴 Unmatched Parentheses:• ```• print("Hello World # SyntaxError: Missing closing quote• ```
  • 5.
    Runtime Errors inPython• ⚠️Runtime errors occur **during programexecution**.• ✅ Fixing Runtime Errors:• - Always check for invalid operations (e.g.,division by zero).• - Ensure variables are defined before use.
  • 6.
    Example of RuntimeErrors• 🔴 Division by Zero:• ```• num = 5• print(num / 0) # ZeroDivisionError• ```• ✅ Fix:• ```• if num != 0:• print(num / 2)• else:• print("Cannot divide by zero")• ```
  • 7.
    Logical Errors inPython• 🔸 Logical errors do not crash the program, butthey produce incorrect output.• ✅ How to Identify Logical Errors:• - Use `print()` statements to track variablevalues.• - Debug with small test cases before runninglarge programs.
  • 8.
    Example of LogicalErrors• 🔴 Incorrect Formula for Average Calculation:• ```• a, b, c = 10, 20, 30• average = a + b + c / 3 # Wrong formula• print("Average:", average)• ```• ✅ Correct Formula:• ```• average = (a + b + c) / 3• print("Average:", average)• ```
  • 9.
    Debugging Techniques inPython• ✅ Common Debugging Methods:• 1. Using `print()` statements.• 2. Using Python's built-in debugger (`pdb`).• 3. Using an IDE with debugging tools.
  • 10.
    Example of Debuggingwith print()• ```• x = 10• print("Value of x:", x) # Debugging usingprint()• ```
  • 11.
    Example of Debuggingwith pdb• ```• import pdb• def add(a, b):• pdb.set_trace() # Debugging starts here• return a + b• result = add(5, 10)• print("Result:", result)• ```
  • 12.
    Summary and KeyTakeaways• - **Syntax errors**: Code structure mistakes,easily fixed.• - **Runtime errors**: Happen duringexecution (e.g., division by zero).• - **Logical errors**: Cause incorrect resultswithout crashing.• - Debugging techniques: `print()`, `pdb`, andusing an IDE for error detection.
  • 13.
    Activity - Fixthe Errors• ❓ Identify and fix the errors in the followingcode:• ```• num = input("Enter a number: ")• print("The square is: " + num * num)• ```• ✅ Hint: Fix data type errors.

[8]ページ先頭

©2009-2025 Movatter.jp