0% found this document useful (0 votes)
4 views

Python Problem Based Learning

The document outlines four different systems: an E-Commerce Cart System, a Library Management System, a Hotel Reservation System, and a Student Grading System, each with specified use cases and modular components. Each system includes a main script and several modules to manage various functionalities such as product management, book transactions, room bookings, and student grading. The document provides code snippets demonstrating the implementation of these systems in Python.

Uploaded by

vishakha120106
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Problem Based Learning

The document outlines four different systems: an E-Commerce Cart System, a Library Management System, a Hotel Reservation System, and a Student Grading System, each with specified use cases and modular components. Each system includes a main script and several modules to manage various functionalities such as product management, book transactions, room bookings, and student grading. The document provides code snippets demonstrating the implementation of these systems in Python.

Uploaded by

vishakha120106
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Vishakha Gite Roll No.

: 22203B0035

Python Problem Based Learning


E-Commerce Cart System
Use Case:
An online shopping site needs a simple shopping cart feature.
Modules:
 product.py: Manage products (name, price, stock).
 cart.py: Add/remove products, view cart total.
 discounts.py: Apply coupon codes and discounts.
 payment.py: Simulate payment processing.

# main.py
from product import *
from cart import *
from discounts import *
from payment import *

def main():
product.add_product("Laptop", 1000, 5)
product.add_product("Phone", 500, 10)
cart.add_to_cart("Laptop", 1)
print("Cart:", cart.view_cart())
total = sum(product.get_product(name)['price'] * qty for name, qty in
cart.view_cart().items())
total = discounts.apply_discount(total, "SAVE10")
payment.process_payment(total)

# product.py
def add_product(name, price, stock):
products[name] = {'price': price, 'stock': stock}
def get_product(name):
return products.get(name, None)

# cart.py
def add_to_cart(name, quantity):
if name in product.products and product.products[name]['stock'] >= quantity:
cart[name] = cart.get(name, 0) + quantity
product.products[name]['stock'] -= quantity
else:
print("Not enough stock available.")
def remove_from_cart(name):
if name in cart:
product.products[name]['stock'] += cart[name]
Name: Vishakha Gite Roll No.: 22203B0035

del cart[name]
def view_cart():
return cart

# discounts.py
discount_codes = {"SAVE10": 0.10, "SAVE20": 0.20}
def apply_discount(total, code):
return total * (1 - discount_codes.get(code, 0))

# payment.py
def process_payment(amount):
print(f"Processing payment of ${amount}...")
return True

Library Management System


Use Case:
A school/college library wants to automate book issue/return management.
Modules:
 book.py: Functions to add, remove, search for books.
 member.py: Functions to add members, check borrowing limits.
 transaction.py: Issue, return, calculate overdue fines.
 reports.py: Generate reports (issued books, fines due).

# main.py
from book import *
from member import *
from transaction import *
from reports import *

def main():
add_book("Python Programming", "John Doe")
add_member("Alice", 1)
issue_book(1, "Python Programming")
print("Library Report:", generate_report())

# book.py
def add_book(title, author):
books[title] = author
def get_books():
return books

# member.py
def add_member(name, member_id):
Name: Vishakha Gite Roll No.: 22203B0035

members[member_id] = name
def get_members():
return members

# transaction.py
def issue_book(member_id, book_title):
if book_title in books:
issued_books[member_id] = book_title
def return_book(member_id):
if member_id in issued_books:
del issued_books[member_id]

# reports.py
def generate_report():
return issued_books

Hotel Reservation System


Use Case:
A hotel booking application where users book rooms, check availability, and manage
payments.
Modules:
 rooms.py: Manage room types, availability.
 booking.py: Reserve/cancel bookings.
 billing.py: Calculate charges, generate bills.
 customer.py: Customer registration and login.

# main.py
from rooms import *
from booking import *
from billing import *
from customer import *

def main():
add_room(101, "Deluxe")
add_customer("Bob", "[email protected]")
if reserve_room(101):
print("Room 101 reserved.")
print("Charge:", calculate_charge(3, 100))

# rooms.py
def add_room(room_number, room_type):
rooms[room_number] = room_type
def check_availability(room_number):
Name: Vishakha Gite Roll No.: 22203B0035

return room_number in rooms

# booking.py
def reserve_room(room_number):
if check_availability(room_number):
bookings[room_number] = "Reserved"
return True
return False
def cancel_booking(room_number):
if room_number in bookings:
del bookings[room_number]

# billing.py
def calculate_charge(nights, rate):
return nights * rate

# customer.py
def add_customer(name, email):
customers[email] = name
def get_customers():
return customers

Student Grading System


Use Case:
A teacher needs an app to calculate grades, store student info, and generate reports.
Modules:
 student.py: Student details (name, roll number).
 marks.py: Add marks, calculate total and average.
 grading.py: Assign grades based on total marks.
 report.py: Generate report cards.

# main.py
from student import *
from marks import *
from grading import *
from report import *

def main():
add_student("Charlie", 101)
add_marks(101, "Math", 85)
add_marks(101, "Science", 90)
print(generate_report(101))
Name: Vishakha Gite Roll No.: 22203B0035

# student.py
def add_student(name, roll_number):
students[roll_number] = name
def get_students():
return students

# marks.py
def add_marks(roll_number, subject, score):
if roll_number not in marks:
marks[roll_number] = {}
marks[roll_number][subject] = score
def get_marks(roll_number):
return marks.get(roll_number, {})

# grading.py
def assign_grade(score):
if score >= 90:
return 'A'
elif score >= 80:
return 'B'
elif score >= 70:
return 'C'
elif score >= 60:
return 'D'
else:
return 'F'

# report.py
def generate_report(roll_number):
student_marks = get_marks(roll_number)
grades = {subject: assign_grade(score) for subject, score in student_marks.items()}
return {"marks": student_marks, "grades": grades}

You might also like