Created
January 30, 2023 14:21
-
-
Save mhassanist/8b3e730277dcf1298a6739e5ea000700 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product: | |
def __init__(self, name, price): | |
self.name = name | |
self.price = price | |
class Cart: | |
def __init__(self): | |
self.items = [] | |
def add_item(self, product): | |
self.items.append(product) | |
def remove_item(self, product): | |
self.items.remove(product) | |
def total(self): | |
total = 0 | |
for item in self.items: | |
total += item.price | |
return total | |
cart = Cart() | |
product1 = Product("Shampoo", 5.99) | |
product2 = Product("Toothpaste", 3.49) | |
cart.add_item(product1) | |
cart.add_item(product2) | |
print("Total: $", cart.total()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment