File tree Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
17
+
18
+
19
+
20
+
21
+
22
+
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments