-
Notifications
You must be signed in to change notification settings - Fork 0
/
Super_market_project.py
177 lines (153 loc) · 6.38 KB
/
Super_market_project.py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
class Supermarket:
product_det = []
def __init__(self, store_name):
self.store_name = store_name
@staticmethod
def listen_audio(products):
from win32com.client import Dispatch
speaker = Dispatch("Sapi.SpVoice")
for items in products:
speaker.Speak(f"Item number{items}")
def display_products(self):
self.product_det = []
with open("Products_available") as p:
for product_description in p:
self.product_det.append(product_description)
choice = input("Do you want to listen the available products or wanna see??\n")
if choice == "listen":
print("Following are the available items!!")
self.listen_audio(self.product_det)
elif choice == "see":
print("Following are the available items!!")
print("Sno.//Items//Price_amount")
for items in self.product_det:
print(items.rstrip())
else:
print("Invalid request!!")
def order_products(self):
order_det = []
quantities = []
product = []
prices = []
flag = True
customer_name = input("What's your name??\n")
product_det = []
available = None
with open("Products_available") as p:
for product_description in p:
product_det.append(product_description)
while flag:
product_name = input("Enter the product you want to buy\n")
product.append(product_name)
for products in product_det:
if products.split("-")[1].lower() == product_name:
available = True
quantity = float(input("Enter how much quantity do you want??\n"))
quantities.append(quantity)
price = int(products.split('-')[2]) * quantity
prices.append(price)
order_det.append(price)
order_det.append(quantity)
break
else:
available = False
if available == False:
print("Not available!!")
discount = [self.discount(pri, quan) for pri, quan in zip(prices, quantities)]
choice = input("Do you want to go for any other product(Yes/No)??\n")
if choice.lower() == 'yes':
flag = True
elif choice.lower() == 'no' and available==True:
return self.generate_bill(customer_name, product, quantities, prices, discount)
else:
print("No bill required!!")
flag = False
@staticmethod
def discount(price, quantity):
if quantity >= 2 and quantity <= 5:
discounted_price = price*0.3
elif quantity > 5 and quantity <=10:
discounted_price = price*0.5
else:
discounted_price = price
return discounted_price
@staticmethod
def generate_bill(name, item, quantity, price, discount):
print("\t\t*******INVOICE*******\t\t")
print(f"Customer Name:{name}")
print("Sno.\tItem-Name\tQuantity\tPrice\tDiscounted-Price")
for i in range(0, len(item)):
print(f" {i+1} \t\t{item[i]} \t\t{quantity[i]} \t\t{price[i]} \t\t{discount[i]}")
print("Thank you!!For Shopping from our store,Hope you liked the service.\n")
@staticmethod
def add_item():
item = []
number = int(input("How many items do you want to add??\n"))
f = open("Products_available", "r")
for lines in f:
item.append(lines)
for i in range(number):
name = input("Name of the product\n")
price = input("Enter the price of the product\n")
with open("Products_available", "a") as p:
p.write(f"{len(item) + 1}-{name}-{price}\n")
print("Products added successfully!!")
def del_item(self):
delete = True
p_name = input("Enter the name of the product you want to delete\n")
file = "updated_Products_available"
self.product_det = []
with open("Products_available") as p:
for product_description in p:
self.product_det.append(product_description)
for prod in self.product_det:
if p_name.lower() == prod.split("-")[1].lower():
self.product_det.remove(prod)
delete = True
break
else:
delete = False
if delete == False:
print("Not available!!")
for items1 in self.product_det:
updated_file = open(file, "w")
updated_file.write(items1)
updated_file.close()
if delete == True:
print("File updated successfully!!")
else:
pass
return file
if __name__ == '__main__':
while True:
role = input("Enter your designation(customer/owner)\n")
if role.lower() == "customer":
customer = Supermarket("Walmart")
choice1 = int(input("Enter what do you want to do??\n"
"1.See/listen product list\n"
"2.Order product\n"))
if choice1 == 1:
customer.display_products()
elif choice1 == 2:
customer.order_products()
else:
print("Invalid request!!")
elif role.lower() == "owner":
owner = Supermarket("Walmart")
choice2 = int(input("Enter what do you want to do??\n1.See/listen product list\n2.Add product"
"\n3.Delete product\n"))
if choice2 == 1:
owner.display_products()
if choice2 == 2:
owner.add_item()
if choice2 == 3:
new = owner.del_item()
ch = input("Do you want to see the updated list(y/n)??\n")
if ch =='y':
print("Following are the available items!!")
print("Sno. Items Price_amount")
with open(new) as u:
for lines in u:
print(lines.rstrip())
else:
pass