Course Content
Programming Foundations Topics:
-Introduction to Python -Installing Python & Setting Up IDE -Variables, Data Types & Operators -Input & Output -Conditional Statements (if, else, elif) -Loops (for, while) -Functions and Parameters -Error Handling (Try/Except)
0/9
Web Development with Python
Topics: Introduction to Flask Introduction to Django Building Your First Web App Routing and Templates Handling Forms Connecting to Databases (SQLite/MySQL) User Authentication Deploying Python Apps Online
Data Science & AI
Topics: Python for Data Analysis Numpy & Pandas Basics Data Cleaning Techniques Data Visualization (Matplotlib, Seaborn) Introduction to Machine Learning (Scikit-Learn) Supervised vs Unsupervised Learning Linear Regression, KNN, and Decision Trees Basic Neural Networks
Automation & Scripting
Topics: Automating Files and Folders Sending Emails with Python Web Scraping (BeautifulSoup, Selenium) Working with Excel & CSV files Scheduling Tasks with Python Scripts PDF and Image Manipulation
Game Development
Topics: Intro to Pygame Creating a Game Window Sprite Movement & Collision Score Tracking Sound and Music in Games Game Projects: Pong, Snake, Flappy Bird
Career & Interview Prep
Topics: Common Python Coding Problems String & List Manipulation Challenges Recursion & Algorithm Practice Big-O Notation Basics Cracking Python Interview Questions Building a Python Portfolio
Advanced Python
Topics: Object-Oriented Programming (OOP) Working with APIs (REST APIs, JSON) Unit Testing with unittest File Handling (Text, JSON, Pickle) Decorators, Generators, and Lambda Functions Multithreading & Asynchronous Programming
Python Full Course

📝 Overview

Programs sometimes crash due to unexpected errors — like dividing by zero or receiving the wrong input. In this lesson, you’ll learn how to use try, except, and other error handling tools to make your programs safe and stable.


🎯 What You’ll Learn

  • What runtime errors are

  • How to handle errors using try and except

  • How to use else and finally blocks

  • Real-world examples of error-proof code


⚠️ 1. What is an Error?

Errors in Python are categorized into:

  • Syntax errors: Mistakes in the code structure (e.g., missing :)

  • Runtime errors: Problems that happen while the program is running (e.g., dividing by 0, inputting letters instead of numbers)


2. Common Runtime Errors

python
# ZeroDivisionError
print(10 / 0)

# ValueError
age = int(input("Enter your age: ")) # if user types "hello"

These errors stop your program unless you handle them.


🧯 3. Handling Errors with try and except

python
try:
age = int(input("Enter your age: "))
print("You are", age, "years old.")
except ValueError:
print("Please enter a valid number.")

✅ The try block runs your main code
✅ If an error happens, the except block runs instead


🔁 4. else and finally (Optional)

  • else: runs if there was no error

  • finally: always runs, error or not

python
try:
num = int(input("Enter a number: "))
except ValueError:
print("Invalid input!")
else:
print("Thank you!")
finally:
print("Program finished.")

🧠 5. Why Use Error Handling?

  • Prevents program crashes

  • Makes user experience smoother

  • Helps debug problems more easily


🧪 Practice Task

Ask the user for a number and print its square. If they enter invalid input, show a message.

python
try:
num = int(input("Enter a number: "))
print("Square is:", num * num)
except ValueError:
print("That’s not a valid number.")

⚠️ Mini Challenge

Create a login system:

  • Ask for username

  • If it’s empty, print "Username cannot be blank"

python
try:
username = input("Enter username: ")
if username == "":
raise Exception("Username cannot be blank")
print("Welcome,", username)
except Exception as e:
print("Error:", e)

Summary

  • Use try and except to catch errors and avoid crashes

  • Add else to run only if there are no errors

  • Use finally to always run cleanup code

  • Real apps need safe error handling!