Python Programming Course (Basic to Intermediate)
For Class 11-12 Students
==================================================
Module 1: Introduction to Python
#1.1 What is Python?
- Python is a versatile, high-level programming language.
- Key features: Simple syntax, cross-platform, large community support.
#1.2 Basic Syntax
Example:
print("Hello, World!")
name = input("Enter your name: ")
print("Welcome,", name)
#1.3 Data Types
- Integers (int), floats (float), strings (str), booleans (bool).
Example:
age = 18
price = 99.99
message = "Learn Python!"
==================================================
Module 2: Control Flow
#2.1 Conditional Statements (if-elif-else)
Example:
marks = 85
if marks >= 90:
print("Grade: A")
elif marks >= 75:
print("Grade: B")
else:
print("Grade: C")
#2.2 Loops (for/while)
Example (Prime Checker):
num = 29
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
print(is_prime) # Output: True
==================================================
Module 3: Data Structures
#3.1 Lists
Example:
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
#3.2 Dictionaries
Example:
student = {"name": "Alice", "age": 20}
print(student["name"]) # Output: Alice
#3.3 Sets
Example:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1.intersection(set2)) # Output: {3}
==================================================
Module 4: Functions
#4.1 Defining Functions
Example:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
print(factorial(5)) # Output: 120
#4.2 Lambda Functions
Example:
square = lambda x: x ** 2
print(square(4)) # Output: 16
==================================================
Module 5: File Handling
#5.1 Reading/Writing Files
Example:
with open("diary.txt", "w") as file:
file.write("Today was a great day!")
with open("diary.txt", "r") as file:
print(file.read()) # Output: Today was a great day!
==================================================
Module 6: Error Handling
#6.1 Try-Except-Finally
Example:
try:
result = 10 / 0
except ZeroDivisionError:
print("Error: Division by zero!")
finally:
print("Execution complete.")
==================================================
Module 7: Object-Oriented Programming (OOP)
#7.1 Classes and Objects
Example:
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
rect = Rectangle(5, 3)
print(rect.area()) # Output: 15
==================================================
Module 8: Optimization Techniques
#8.1 Time Complexity
- Use sets for membership checks (O(1) time).
Example:
names = {"Alice", "Bob", "Charlie"}
if "Alice" in names: # Faster than using a list
print("Found!")
#8.2 Efficient Loops
- Prefer list comprehensions.
Example:
squares = [x**2 for x in range(10)] # Faster than a for loop
==================================================
Module 9: Mini Projects
#9.1 Simple Calculator
Example:
def add(a, b):
return a + b
def subtract(a, b):
return a - b
# Add a menu-driven interface here.
#9.2 Quiz Game
Example:
questions = {
"What is 2+2?": "4",
"Capital of France?": "Paris"
score = 0
for q, a in questions.items():
user_ans = input(q)
if user_ans == a:
score += 1
print("Your score:", score)
==================================================
Module 10: Advanced Topics (Optional)
#10.1 Libraries (NumPy, Pandas)
Example (Pandas):
import pandas as pd
data = {"Name": ["Alice", "Bob"], "Age": [20, 22]}
df = pd.DataFrame(data)
print(df)
#10.2 Algorithms (Binary Search)
Example:
def binary_search(arr, target):
low, high = 0, len(arr)-1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
print(binary_search([1, 3, 5, 7, 9], 7)) # Output: 3
==================================================