-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSHOP.py
More file actions
122 lines (108 loc) · 3.34 KB
/
SHOP.py
File metadata and controls
122 lines (108 loc) · 3.34 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
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
class Product:
def __init__(self, name, price, year):
self.name = name
self.price = price
self.year = year
self.type = ''
class Shop:
def __init__(self, title, phone):
self.title = title
self.phone = phone
self.baza = []
self.drink = []
self.fruit = []
self.food = []
def add_drink(self):
title = input("title: ")
price = input("price: $")
year = input("year: ")
p = Product(title, price, year)
p.type = "drink"
self.baza.append(p)
self.drink.append(p)
def add_food(self):
title = input("title: ")
price = input("price: $")
year = input("year: ")
p = Product(title, price, year)
p.type = "food"
self.baza.append(p)
self.food.append(p)
def add_fruit(self):
title = input("title: ")
price = input("price: $")
year = input("year: ")
p = Product(title, price, year)
p.type = "fruit"
self.baza.append(p)
self.fruit.append(p)
def view_all(self):
for i, item in self.baza:
i+=1
print(f"{i}. {item.type} {item.name} {item.price} {item.year}")
def view_drink(self):
for item in self.drink:
print(item.name, item.price, item.year)
def view_food(self):
for item in self.food:
print(item.name, item.price, item.year)
def view_fruit(self):
for item in self.fruit:
print(item.name, item.price, item.year)
def update(self):
self.view_all()
index = int(input("raqam kiriting: ")) - 1
product = self.baza[index]
print("Nimani yangilamoqchisiz?")
print("1. Name\n2. Price\n3. Year")
choice = input("Tanlov: ")
if choice == "1":
product.name = input("Yangi nom: ")
elif choice == "2":
product.price = input("Yangi narx: ")
elif choice == "3":
product.year = input("Yangi yil: ")
else:
print("Noto'g'ri tanlov!")
return
print("Ma'lumot yangilandi!")
def delete(self):
self.view_all()
index = int(input("Qaysi mahsulotni o'chirasiz? Raqam: ")) - 1
if 0 <= index < len(self.baza):
item = self.baza.pop(index)
if item.type == "drink":
self.drink.remove(item)
elif item.type == "food":
self.food.remove(item)
elif item.type == "fruit":
self.fruit.remove(item)
print("O'chirildi!")
else:
print("Xato raqam!")
shopping=Shop("Karzinka",909998998)
def manage(a:Shop):
while True:
print("1.view all\n2.view_drink\n3.view_food\n4.view_fruit\n5.add_fruit\n6.add_food\n7.add_drink\n8.delete\n9.update\n10.break")
code=input("enter code:")
if code=='1':
a.view_all()
elif code=='2':
a.view_drink()
elif code=='3':
a.view_food()
elif code=='4':
a.view_fruit()
elif code=='5':
a.add_drink()
elif code=='6':
a.add_food()
elif code=='7':
a.add_fruit()
elif code=='8':
a.delete()
elif code=='9':
a.update()
else:
break
manage(shopping)