Tigriptv

Introduction

The current image has no alternative text. The file name is: ESLA.jpg

Errors are a normal part of programming. In Python, you will encounter two main types of errors:

  1. Syntax Errors – mistakes in the structure of your code.
  2. Exceptions – errors that occur while the program is running.

Python provides a powerful way to handle exceptions so your program doesn’t crash.


Common Errors in Python

Error TypeExample CodeExplanation
SyntaxErrorprint("Hello"Missing parenthesis.
ZeroDivisionError10 / 0Cannot divide by zero.
NameErrorprint(x) (x not defined)Using a variable that doesn’t exist.
TypeError"5" + 2Mixing incompatible data types.
ValueErrorint("abc")Invalid value for type conversion.

Basic Exception Handling

try:
    number = int(input("Enter a number: "))
    result = 10 / number
    print("Result:", result)
except ZeroDivisionError:
    print("Error: You cannot divide by zero.")
except ValueError:
    print("Error: Please enter a valid number.")

✅ If the user enters 0, it catches ZeroDivisionError.
✅ If the user enters "abc", it catches ValueError.


Using else and finally

try:
    num = int(input("Enter a number: "))
    print("Square:", num ** 2)
except ValueError:
    print("Invalid input. Enter a number.")
else:
    print("Operation successful!")   # runs if no error
finally:
    print("Program ended.")          # always runs
  • else: Runs only if no exception occurs.
  • finally: Runs no matter what (useful for cleanup).

Raising Exceptions

You can raise exceptions manually using raise.

age = -5
if age < 0:
    raise ValueError("Age cannot be negative")

Summary

  • Syntax Errors stop the code from running.
  • Exceptions happen during execution.
  • Use try/except to handle errors gracefully.
  • else runs only if no error, finally always runs.
  • You can raise your own exceptions.

Error handling makes programs more robust, safe, and user-friendly.

⬇️ Download Tigriptv تحميل Server 1 ⬇️ Download Tigriptv تحميل Server 2 ⬇️ Download Tigriptv تحميل Server 3

Related Posts

FlyFeditv

📘 Introduction In this project, you’ll create a command-line Expense Tracker that allows users to: ✅ Add expenses with category, amount, and description✅ View total spending and category breakdown✅ Automatically…

Read more

NetCinFly

📘 Introduction In this project, you’ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

🌐 Introduction In this project, you’ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.You’ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

🌦️ Introduction In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.You’ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: 🎯 Objective: Create a simple, text-based contact book application that allows users to: 💡 Code (contact_book.py): 🧠 Example Usage Console Output Example: 💾 Notes ⬇️ Download Show7-Pro تحميل…

Read more

Rapid_tv

🔹 Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. 👉 Rules: 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned…

Read more