-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlineShoppingCart.py
More file actions
32 lines (22 loc) · 1.18 KB
/
OnlineShoppingCart.py
File metadata and controls
32 lines (22 loc) · 1.18 KB
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
class ItemToPurchase:
# Parameterized constructor with default values helping to act like a default constructor
def __init__(self, item_name: str = "none", item_price: float = 0, item_quantity: int = 0):
self.item_name = item_name
self.item_price = item_price
self.item_quantity = item_quantity
# Method to calculate and print the cost.
def print_item_cost(self):
print(f"{self.item_name} {self.item_quantity} @ ${self.item_price:.0f} = ${(self.item_price * self.item_quantity):.0f}")
# Method to calculate and print the total cost.
def print_total(self, other_item):
print("\nTOTAL COST\n")
self.print_item_cost()
other_item.print_item_cost()
print(f"Total: ${((self.item_price * self.item_quantity) + (other_item.item_price * other_item.item_quantity)):.0f}")
# Taking user's input for creating two items.
print("\nItem1\n")
item1 = ItemToPurchase(input("\nEnter the item name:\n"), float(input("\nEnter the item price:\n")), int(input("\nEnter the item quantity:\n")))
print("\nItem2\n")
item2 = ItemToPurchase(input("\nEnter the item name:\n"), float(input("\nEnter the item price:\n")), int(input("\nEnter the item quantity:\n")))
# Printing total
item1.print_total(item2)