forked from fenyx-it-academy/Class4-PythonModule-Week5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek 5-Odev_4.py
More file actions
95 lines (76 loc) · 3.23 KB
/
Week 5-Odev_4.py
File metadata and controls
95 lines (76 loc) · 3.23 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class Items:
total_p = 0
def __init__(self, cust_id=None, item_name=None, price=0, qty=0, total_price=0):
self.cust_id = cust_id
self.item_name = item_name
self.price = price
self.qty = qty
self.total_price = total_price
self.basket = []
def calculate_discount(self):
if Items.total_p >= 4000:
return int(Items.total_p * 0.25)
if Items.total_p >= 2000:
return int(Items.total_p * 0.15)
if Items.total_p < 2000:
return int(Items.total_p * 0.10)
def shopping_cart(self):
print("%" * 22, "YOUR SHOPPING CARD", "%" * 23)
while True:
self.item_name = input("Enter a product name: ")
try:
self.qty = int(input("Enter quantity: "))
self.price = int(input("Enter Price: "))
self.basket.append([self.item_name, self.qty, self.price])
print("Product added to basket..")
except:
print("Enter a integer please..")
q = input("Do you want to continue shopping? (Y/N)").upper()
self.total_price = self.price * self.qty
Items.total_p += self.total_price
if q == "Y":
continue
else:
n = self.basket
for i in n:
print("\nPRODUCT QUANTITY PRICE"
"\n{} x {} {} $"
"\n------------------------------------------------------------------"
.format(i[0], i[1], i[2]))
self.calculate_discount()
self.__str__()
break
def get_total_amount(self):
price_tobe_paid = Items.total_p - Items.calculate_discount(self)
return price_tobe_paid
def __str__(self):
print("Your Shopping List :{} "
"\nSUB TOTAL :{} $ "
"\nDISCOUNT :{} $ "
"\n=================================================================="
"\n TOTAL = {} $ "
.format(self.basket, Items.total_p, Items.calculate_discount(self),
Items.get_total_amount(self)))
class Customer:
customers = []
def __init__(self, customer_id=None, name=None, last_name=None):
self.customer_id = customer_id
self.name = name
self.last_name = last_name
self.get_cust_info()
def get_cust_info(self):
self.customer_id = input("Enter customer_id:")
self.name = input("Enter first name:").upper()
self.last_name = input("Enter last_name:").upper()
self.customers.append([self.customer_id, self.name, self.last_name])
def __str__(self):
for i in Customer.customers:
print("\nCustomer ID :{} "
"\nName :{} "
"\nLast Name :{}".format(i[0], i[1], i[2]))
c1 = Customer()
print("Customers List: ", Customer.customers)
print()
Customer.__str__(c1)
it1 = Items()
it1.shopping_cart()