Spaces:
Sleeping
Sleeping
Rename cart_tab.py to cart.py
Browse files- cart.py +13 -0
- cart_tab.py +0 -18
cart.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Cart:
|
| 2 |
+
def __init__(self):
|
| 3 |
+
self.items = []
|
| 4 |
+
|
| 5 |
+
def add_item(self, item):
|
| 6 |
+
self.items.append(item)
|
| 7 |
+
return f"Added {item['name']} to the cart."
|
| 8 |
+
|
| 9 |
+
def view_cart(self):
|
| 10 |
+
return self.items
|
| 11 |
+
|
| 12 |
+
def total_price(self):
|
| 13 |
+
return sum(item["price"] for item in self.items)
|
cart_tab.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
| 1 |
-
cart = []
|
| 2 |
-
|
| 3 |
-
def add_to_cart(item_name, spice_level, extras):
|
| 4 |
-
cart.append({
|
| 5 |
-
"item_name": item_name,
|
| 6 |
-
"spice_level": spice_level,
|
| 7 |
-
"extras": extras
|
| 8 |
-
})
|
| 9 |
-
return f"{item_name} added to cart!"
|
| 10 |
-
|
| 11 |
-
def display_cart():
|
| 12 |
-
if not cart:
|
| 13 |
-
return "Your cart is empty."
|
| 14 |
-
cart_content = "<h3>Your Cart:</h3><ul>"
|
| 15 |
-
for item in cart:
|
| 16 |
-
cart_content += f"<li>{item['item_name']} - Spice Level: {item['spice_level']} - Extras: {', '.join(item['extras'])}</li>"
|
| 17 |
-
cart_content += "</ul>"
|
| 18 |
-
return cart_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|