Python Problem Based Learning
Python Problem Based Learning
: 22203B0035
# 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
# 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
# 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
# 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
# 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}