-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBill.py
48 lines (39 loc) · 1.34 KB
/
Bill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Item:
def _init_(self, name, price, quantity):
self.name = name
self.price = price
self.quantity = quantity
def calculate_item_total(self):
return self.price
class Bill:
def _init_(self):
self.items = []
def add_item(self, item):
self.items.append(item)
def calculate_total(self):
total = sum(item.calculate_item_total() for item in self.items)
return total
def main():
bill = Bill()
while True:
print("\nOptions:")
print("1. Add item to the bill")
print("2. Print bill and exit")
choice = input("Enter your choice (1/2): ")
if choice == '1':
item_name = input("Enter item name: ")
item_price = float(input("Enter item price: "))
item_quantity = float(input("Enter item quantity(in KG): "))
item = Item(item_name, item_price, item_quantity)
bill.add_item(item)
elif choice == '2':
total = bill.calculate_total()
print("\nBill Summary:")
for item in bill.items:
print(f"{item.name} - Price: ${item.price}, Quantity(in KG): {item.quantity}")
print(f"Total: ${total}")
break
else:
print("Invalid choice. Please choose 1 or 2.")
if _name_ == "_main_":
main()