|
| 1 | +class Store: |
| 2 | + def __init__(self): |
| 3 | + self.products = {} |
| 4 | + |
| 5 | + def add_product(self, code, name, price): |
| 6 | + self.products[code] = {'name': name, 'price': price} |
| 7 | + |
| 8 | + def display_menu(self): |
| 9 | + print("Menu:") |
| 10 | + print("Code\tName\tPrice") |
| 11 | + for code, product in self.products.items(): |
| 12 | + print(f"{code}\t{product['name']}\t₹{product['price']}") |
| 13 | + |
| 14 | + def generate_bill(self, order): |
| 15 | + total_amount = 0 |
| 16 | + print("\n------------------ RECEIPT ------------------") |
| 17 | + print("Code\tName\tPrice\tQuantity\tTotal") |
| 18 | + for code, quantity in order.items(): |
| 19 | + product = self.products[code] |
| 20 | + item_total = quantity * product['price'] |
| 21 | + total_amount += item_total |
| 22 | + print(f"{code}\t{product['name']}\t₹{product['price']}\t{quantity}\t\t₹{item_total}") |
| 23 | + |
| 24 | + print("\nTotal Amount: ₹{:.2f}\n".format(total_amount)) |
| 25 | + |
| 26 | + |
| 27 | +def main(): |
| 28 | + store = Store() |
| 29 | + |
| 30 | + store.add_product('001', 'Bread', 25.00) |
| 31 | + store.add_product('002', 'Chips', 15.00) |
| 32 | + store.add_product('003', 'KitKat', 10.00) |
| 33 | + store.add_product('004', 'Coke', 20.00) |
| 34 | + store.add_product('005', 'Biscuit', 12.00) |
| 35 | + store.add_product('006', 'Butter', 35.00) |
| 36 | + store.add_product('007', 'Rice', 30.00) |
| 37 | + store.add_product('008', 'Lentils', 35.00) |
| 38 | + store.add_product('009', 'Suji', 40.00) |
| 39 | + store.add_product('010', 'Spice', 20.00) |
| 40 | + |
| 41 | + store.display_menu() |
| 42 | + |
| 43 | + order = {} |
| 44 | + while True: |
| 45 | + code = input("Enter the product code (or 'done' to finish): ") |
| 46 | + if code.lower() == 'done': |
| 47 | + break |
| 48 | + elif code in store.products: |
| 49 | + quantity = int(input(f"Enter the quantity for {store.products[code]['name']}: ")) |
| 50 | + order[code] = quantity |
| 51 | + else: |
| 52 | + print("Invalid product code. Please enter a valid code.") |
| 53 | + |
| 54 | + store.generate_bill(order) |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + main() |
0 commit comments