1️.
Problem: Library Management System
class Book:
def __init__(self, title, author, isbn):
self.title = title
self.author = author
self.isbn = isbn
def get_details(self):
return f"Title: {self.title}, Author: {self.author}, ISBN:
{self.isbn}"
class Textbook(Book):
def __init__(self, title, author, isbn, subject):
super().__init__(title, author, isbn)
self.subject = subject
def get_details(self):
return super().get_details() + f", Subject: {self.subject}"
class Novel(Book):
def __init__(self, title, author, isbn, genre):
super().__init__(title, author, isbn)
self.genre = genre
def get_details(self):
return super().get_details() + f", Genre: {self.genre}"
class Magazine(Book):
def __init__(self, title, author, isbn, issue_number):
super().__init__(title, author, isbn)
self.issue_number = issue_number
def get_details(self):
return super().get_details() + f", Issue Number:
{self.issue_number}"
books = [
Textbook("Math Basics", "John Doe", "123456", "Mathematics"),
Novel("The Great Novel", "Jane Doe", "654321", "Fiction"),
Magazine("Tech Today", "Tech Corp", "987654", "Issue 42")
]
for book in books:
print(book.get_details())
Title: Math Basics, Author: John Doe, ISBN: 123456, Subject:
Mathematics
Title: The Great Novel, Author: Jane Doe, ISBN: 654321, Genre: Fiction
Title: Tech Today, Author: Tech Corp, ISBN: 987654, Issue Number:
Issue 42
1. Problem: Vehicle Rental System
class Vehicle:
def __init__(self, brand, model, year):
self.brand = brand
self.model = model
self.year = year
def display_info(self):
return f"Brand: {self.brand}, Model: {self.model}, Year:
{self.year}"
def get_rental_price(self):
raise NotImplementedError("Subclasses must implement this
method")
class Car(Vehicle):
def get_rental_price(self):
return 50
def display_info(self):
return super().display_info() + ", Type: Car"
class Bike(Vehicle):
def get_rental_price(self):
return 20
def display_info(self):
return super().display_info() + ", Type: Bike"
class Truck(Vehicle):
def get_rental_price(self):
return 100
def display_info(self):
return super().display_info() + ", Type: Truck"
vehicles = [
Car("Toyota", "Corolla", 2020),
Bike("Honda", "CBR", 2019),
Truck("Ford", "F-150", 2021)
]
for vehicle in vehicles:
print(vehicle.display_info(), f", Rental Price: $
{vehicle.get_rental_price()} per day")
Brand: Toyota, Model: Corolla, Year: 2020, Type: Car , Rental Price:
$50 per day
Brand: Honda, Model: CBR, Year: 2019, Type: Bike , Rental Price: $20
per day
Brand: Ford, Model: F-150, Year: 2021, Type: Truck , Rental Price:
$100 per day
3️. Problem: Employee Payroll System
from abc import ABC, abstractmethod
class Employee(ABC):
def __init__(self, name, id, base_salary):
self.name = name
self.id = id
self.base_salary = base_salary
@abstractmethod
def calculate_salary(self):
pass
class FullTimeEmployee(Employee):
def __init__(self, name, id, base_salary, bonus):
super().__init__(name, id, base_salary)
self.bonus = bonus
def calculate_salary(self):
return self.base_salary + self.bonus
class PartTimeEmployee(Employee):
def __init__(self, name, id, hourly_rate, hours_worked):
super().__init__(name, id, 0)
self.hourly_rate = hourly_rate
self.hours_worked = hours_worked
def calculate_salary(self):
return self.hourly_rate * self.hours_worked
class Freelancer(Employee):
def __init__(self, name, id, project_rate, projects_completed):
super().__init__(name, id, 0)
self.project_rate = project_rate
self.projects_completed = projects_completed
def calculate_salary(self):
return self.project_rate * self.projects_completed
employees = [
FullTimeEmployee("Alice", "E001", 5000, 1000),
PartTimeEmployee("Bob", "E002", 20, 80),
Freelancer("Charlie", "E003", 500, 3)
]
for employee in employees:
print(f"{employee.name}'s Salary: ${employee.calculate_salary()}")
Alice's Salary: $6000
Bob's Salary: $1600
Charlie's Salary: $1500
4️. Problem: Online Payment System
from abc import ABC, abstractmethod
class Payment(ABC):
@abstractmethod
def process_payment(self, amount):
pass
class CreditCardPayment(Payment):
def process_payment(self, amount):
print(f"Paid ${amount} using Credit Card.")
class PayPalPayment(Payment):
def process_payment(self, amount):
print(f"Paid ${amount} via PayPal.")
class CryptoPayment(Payment):
def process_payment(self, amount):
print(f"Paid ${amount} using Cryptocurrency.")
payments = [
CreditCardPayment(),
PayPalPayment(),
CryptoPayment()
]
amount = 100
for payment in payments:
payment.process_payment(amount)
Paid $100 using Credit Card.
Paid $100 via PayPal.
Paid $100 using Cryptocurrency.
1. Problem: Smart Home Automation
from abc import ABC, abstractmethod
class Appliance(ABC):
def __init__(self, name, power_consumption):
self.name = name
self.power_consumption = power_consumption
@abstractmethod
def turn_on(self):
pass
class Light(Appliance):
def turn_on(self):
print("Light is turned ON.")
class Fan(Appliance):
def turn_on(self):
print("Fan is running.")
class AirConditioner(Appliance):
def turn_on(self):
print("AC is cooling the room.")
appliances = [
Light("Living Room Light", 50),
Fan("Ceiling Fan", 100),
AirConditioner("Bedroom AC", 500)
]
for appliance in appliances:
appliance.turn_on()
Light is turned ON.
Fan is running.
AC is cooling the room.