Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e5b85cd

Browse filesBrowse files
committed
broken grocery store app
1 parent 5e4e62c commit e5b85cd
Copy full SHA for e5b85cd

File tree

Expand file treeCollapse file tree

5 files changed

+43
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+43
-0
lines changed
Open diff view settings
Collapse file

‎app.py‎

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from grocery_store.product import Product
2+
from grocery_store.order import Order
3+
4+
5+
kamala_order = Order([], "Kamala")
6+
7+
product_1 = Product("Apples", 3.47)
8+
product_2 = Product("Oranges", 4.89)
9+
product_3 = Product("Macbook", 1379.99)
10+
11+
kamala_order.add_product(product_1)
12+
kamala_order.add_product(product_2)
13+
kamala_order.add_product(product_3)
14+
15+
print(f"The order total for {kamala_order.customer_name} is " +
16+
f"{kamala_order.calculate_total()}")
17+
Collapse file
899 Bytes
Binary file not shown.
Collapse file
597 Bytes
Binary file not shown.
Collapse file

‎grocery_store/order.py‎

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from grocery_store.product import Product
2+
3+
class Order:
4+
def __init__(self, products, customer_name):
5+
self.products = products
6+
self.customer_name = customer_name
7+
8+
def add_product(self, product):
9+
self.products.append(product)
10+
11+
def calculate_total(self):
12+
total = 0
13+
for i in range(1, len(self.products)):
14+
total += self.products[i].price
15+
16+
return total
Collapse file

‎grocery_store/product.py‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Product:
2+
def __init__(self, name, price):
3+
self.name = name
4+
self.price = name
5+
6+
7+
def __str__(self):
8+
return f"{self.name} - ${self.price}"
9+
10+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.