# Program 1: Library Management (with input)
class Book:
def __init__(self, title, author, available=True):
[Link] = title
[Link] = author
[Link] = available
def __str__(self):
return f"{[Link]} by {[Link]} [{'Available' if [Link] else
'Checked-out'}]"
class Library:
def __init__(self):
[Link] = []
def add_book(self, book):
[Link](book)
def find(self, title):
for b in [Link]:
if [Link]() == [Link]():
return b
return None
def checkout(self, title):
b = [Link](title)
if not b: return "Book not found"
if not [Link]: return "Already issued"
[Link] = False
return "Issued successfully"
def return_book(self, title):
b = [Link](title)
if not b: return "Book not found"
[Link] = True
return "Returned successfully"
def list_books(self):
print("
".join(map(str, [Link])) if [Link] else "No books")
def library_ui():
lib = Library()
while True:
print("
Library Menu: [Link] [Link] [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
t = input("Title: "); a = input("Author: ")
lib.add_book(Book(t, a)); print("Added")
elif ch == "2":
lib.list_books()
elif ch == "3":
t = input("Title to checkout: ")
print([Link](t))
elif ch == "4":
t = input("Title to return: ")
print(lib.return_book(t))
elif ch == "5":
break
else:
print("Invalid")
# Run this function to test Program 1
# library_ui()
# Program 2: Banking System (with input)
class Account:
def __init__(self, owner, balance=0.0):
[Link] = owner
[Link] = float(balance)
def deposit(self, amount):
if amount <= 0: return "Invalid deposit"
[Link] += amount; return f"Balance ₹{[Link]:.2f}"
def withdraw(self, amount):
if amount <= 0: return "Invalid withdraw"
if amount > [Link]: return "Insufficient funds"
[Link] -= amount; return f"Balance ₹{[Link]:.2f}"
def __str__(self):
return f"{[Link]}: ₹{[Link]:.2f}"
class SavingsAccount(Account):
def __init__(self, owner, balance=0.0, rate=0.04):
super().__init__(owner, balance); [Link] = rate
def add_interest(self):
[Link] += [Link] * [Link]
return f"Interest added, Balance ₹{[Link]:.2f}"
def banking_ui():
t = input("Type (account/savings): ").strip().lower()
owner = input("Owner: ")
bal = float(input("Opening balance: "))
acc = SavingsAccount(owner, bal) if t == "savings" else Account(owner, bal)
while True:
print("
Bank Menu: [Link] [Link] [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
amt = float(input("Amount: "))
print([Link](amt))
elif ch == "2":
amt = float(input("Amount: "))
print([Link](amt))
elif ch == "3":
if isinstance(acc, SavingsAccount): print(acc.add_interest())
else: print("Only for SavingsAccount")
elif ch == "4":
print(acc)
elif ch == "5":
break
else:
print("Invalid")
# banking_ui()
# Program 3: Shape Hierarchy (with input)
import math
class Shape:
def area(self): raise NotImplementedError
class Circle(Shape):
def __init__(self, r): self.r = r
def area(self): return [Link] * self.r * self.r
class Rectangle(Shape):
def __init__(self, w, h): self.w, self.h = w, h
def area(self): return self.w * self.h
def shapes_ui():
while True:
print("
Shapes: [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
r = float(input("Radius: "))
print(f"Area = {Circle(r).area():.2f}")
elif ch == "2":
w = float(input("Width: "))
h = float(input("Height: "))
print(f"Area = {Rectangle(w, h).area():.2f}")
elif ch == "3":
break
else:
print("Invalid")
# shapes_ui()
# Program 4: Employee Management (with input)
class Employee:
def __init__(self, name, base_salary): [Link], self.base_salary = name,
base_salary
def monthly_pay(self): return self.base_salary
def __str__(self): return f"{[Link]}: ₹{self.monthly_pay():.2f}"
class Manager(Employee):
def __init__(self, name, base_salary, allowance): super().__init__(name,
base_salary); [Link] = allowance
def monthly_pay(self): return self.base_salary + [Link]
class Developer(Employee):
def __init__(self, name, base_salary, projects, bonus_per_project=3000):
super().__init__(name, base_salary); [Link] = projects;
self.bonus_per_project = bonus_per_project
def monthly_pay(self): return self.base_salary + [Link] *
self.bonus_per_project
def employee_ui():
while True:
print("
Employees: [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
n = input("Name: "); bs = float(input("Base salary: ")); al =
float(input("Allowance: "))
print(Manager(n, bs, al))
elif ch == "2":
n = input("Name: "); bs = float(input("Base salary: ")); p =
int(input("Projects: "))
print(Developer(n, bs, p))
elif ch == "3":
break
else:
print("Invalid")
# employee_ui()
# Program 5: Method Overloading Simulation (with input)
class MathOps:
@staticmethod
def add(*args):
if len(args) == 1 and hasattr(args[0], "__iter__"):
return sum(args[0])
if all(isinstance(x, (int, float)) for x in args) and 2 <= len(args) <= 3:
return sum(args)
raise TypeError("Use: add(a,b) | add(a,b,c) | add(iterable)")
def math_ui():
while True:
print("
Add: [Link] [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
a = float(input("a: ")); b = float(input("b: "))
print("Sum =", [Link](a, b))
elif ch == "2":
a = float(input("a: ")); b = float(input("b: ")); c = float(input("c:
"))
print("Sum =", [Link](a, b, c))
elif ch == "3":
s = input("Enter numbers comma-separated: ")
nums = [float(x) for x in [Link](",") if [Link]()]
print("Sum =", [Link](nums))
elif ch == "4":
break
else:
print("Invalid")
# math_ui()
# Program 6: Notification System (with input)
class Notifier:
def send(self, message): raise NotImplementedError
class EmailNotifier(Notifier):
def __init__(self, email): [Link] = email
def send(self, message): return f"Email to {[Link]}: {message}"
class SMSNotifier(Notifier):
def __init__(self, phone): [Link] = phone
def send(self, message): return f"SMS to {[Link]}: {message}"
class NotificationService:
def __init__(self, notifiers): [Link] = notifiers
def notify_all(self, message):
return [[Link](message) for n in [Link]]
def notify_ui():
notifiers = []
if input("Use Email? (y/n): ").strip().lower() == "y":
[Link](EmailNotifier(input("Email: ").strip()))
if input("Use SMS? (y/n): ").strip().lower() == "y":
[Link](SMSNotifier(input("Phone: ").strip()))
if not notifiers:
print("No channels selected"); return
msg = input("Message: ")
for line in NotificationService(notifiers).notify_all(msg):
print(line)
# notify_ui()
# Program 7: Area Calculator with single API (with input)
import math
class Area:
@staticmethod
def calc(shape, *params):
s = [Link]()
if s == "circle" and len(params) == 1:
r, = params; return [Link] * r * r
if s == "rectangle" and len(params) == 2:
w, h = params; return w * h
if s == "triangle" and len(params) == 2:
b, h = params; return 0.5 * b * h
raise ValueError("Unsupported shape/params")
def area_ui():
while True:
print("
Shapes: circle | rectangle | triangle | exit")
s = input("Shape: ").strip().lower()
if s == "exit": break
try:
if s == "circle":
r = float(input("Radius: ")); print(f"Area = {[Link](s,
r):.2f}")
elif s == "rectangle":
w = float(input("Width: ")); h = float(input("Height: "));
print(f"Area = {[Link](s, w, h):.2f}")
elif s == "triangle":
b = float(input("Base: ")); h = float(input("Height: "));
print(f"Area = {[Link](s, b, h):.2f}")
else:
print("Unknown shape")
except ValueError as e:
print(e)
# area_ui()
# Program 8: E-commerce (with input)
class Product:
def __init__(self, name, price): [Link], [Link] = name, float(price)
def final_price(self, discount=0.0): return [Link] * (1 - discount)
def info(self): return f"{[Link]} ₹{[Link]:.2f}"
class ElectronicProduct(Product):
def __init__(self, name, price, warranty_years=1):
super().__init__(name, price); self.warranty_years = warranty_years
def info(self): return f"{super().info()} | Warranty: {self.warranty_years}y"
class ClothingProduct(Product):
def __init__(self, name, price, size):
super().__init__(name, price); [Link] = size
def info(self): return f"{super().info()} | Size: {[Link]}"
def ecommerce_ui():
items = []
while True:
print("
Add: [Link] [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
n = input("Name: "); p = float(input("Price: ")); w =
int(input("Warranty years: "))
[Link](ElectronicProduct(n, p, w)); print("Added")
elif ch == "2":
n = input("Name: "); p = float(input("Price: ")); s = input("Size: ")
[Link](ClothingProduct(n, p, s)); print("Added")
elif ch == "3":
d = float(input("Discount (0-1): ") or 0.0)
for it in items:
print([Link](), "| Final:", f"₹{it.final_price(d):.2f}")
elif ch == "4":
break
else:
print("Invalid")
# ecommerce_ui()
# Program 9: Course Platform (with input)
class Course:
def __init__(self, title, duration_weeks):
[Link], self.duration_weeks = title, int(duration_weeks)
[Link] = 0
def enroll(self, n=1): [Link] += int(n)
def summary(self): return f"{[Link]} ({self.duration_weeks}w) -
{[Link]} enrolled"
class TechnicalCourse(Course):
def __init__(self, title, duration_weeks, tech):
super().__init__(title, duration_weeks); [Link] = tech
def summary(self): return f"{super().summary()} | Tech: {[Link]}"
class NonTechnicalCourse(Course):
def __init__(self, title, duration_weeks, domain):
super().__init__(title, duration_weeks); [Link] = domain
def summary(self): return f"{super().summary()} | Domain: {[Link]}"
def course_ui():
courses = []
while True:
print("
Courses: [Link] Tech [Link] NonTech [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
t = input("Title: "); d = int(input("Weeks: ")); tech = input("Tech: ")
[Link](TechnicalCourse(t, d, tech)); print("Added")
elif ch == "2":
t = input("Title: "); d = int(input("Weeks: ")); dom = input("Domain:
")
[Link](NonTechnicalCourse(t, d, dom)); print("Added")
elif ch == "3":
if not courses: print("No courses"); continue
for i, c in enumerate(courses): print(i, "-", [Link]())
idx = int(input("Index to enroll: ")); n = int(input("Count: "))
courses[idx].enroll(n); print("Enrolled")
elif ch == "4":
for c in courses: print([Link]())
elif ch == "5":
break
else:
print("Invalid")
# course_ui()
# Program 10: Vehicle Rental (with input)
class Vehicle:
def __init__(self, reg_no, daily_rate): self.reg_no, self.daily_rate = reg_no,
float(daily_rate)
def cost(self, days): return int(days) * self.daily_rate
class Car(Vehicle):
def __init__(self, reg_no, daily_rate, seats): super().__init__(reg_no,
daily_rate); [Link] = int(seats)
def __str__(self): return f"Car {self.reg_no} ({[Link]} seats)"
class Bike(Vehicle):
def __init__(self, reg_no, daily_rate, cc): super().__init__(reg_no,
daily_rate); [Link] = int(cc)
def __str__(self): return f"Bike {self.reg_no} ({[Link]}cc)"
def rental_ui():
while True:
print("
Rent: [Link] [Link] [Link]")
ch = input("Choice: ").strip()
if ch == "1":
r = input("Reg no: "); rate = float(input("Daily rate: ")); s =
int(input("Seats: "))
v = Car(r, rate, s)
elif ch == "2":
r = input("Reg no: "); rate = float(input("Daily rate: ")); cc =
int(input("CC: "))
v = Bike(r, rate, cc)
elif ch == "3":
break
else:
print("Invalid"); continue
d = int(input("Days: "))
print(f"{v}: {d} days → ₹{[Link](d):.2f}")
# rental_ui()