-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsupermarket management 1.py
98 lines (91 loc) · 3.91 KB
/
supermarket management 1.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
#-----------------SUPERMARKET MANAGEMENT SYSTEM--------------------
items = []
while True:
display = input('Press enter to continue.')
print('------------------Welcome to the supermarket------------------')
print('1. View items\n2. Add items for sale\n3. Purchase items\n4. Search items \n5. Edit items\n6. Exit')
choice = input('Enter the number of your choice : ')
if choice == '1' :
print('------------------View Items------------------')
print('The number of items in the inventory are : ',len(items))
while len(items) != 0:
print('Here are all the items available in the supermarket.')
for item in items:
for key, value in item.items():
print(key, ':', value)
break
elif choice == '2' :
print('------------------Add items------------------')
print('To add an item fill in the form')
# while True:
# try:
# number_items = int(input('Enter the number of items you want to add in the inventory : '))
# break
# except ValueError:
# print('Number of items should only be in digits')
# for num in range(number_items):
item = {}
item['name'] = input('Item name : ')
while True:
try:
item['quantity'] = int(input('Item quantity : '))
break
except ValueError:
print('Quantity should only be in digits')
while True:
try:
item['price'] = int(input('Price $ : '))
break
except ValueError:
print('Price should only be in digits')
print('Item has been successfully added.')
items.append(item)
elif choice == '3' :
print('------------------purchase items------------------')
print(items)
purchase_item = input('which item do you want to purchase? Enter name : ')
for item in items:
if purchase_item.lower() == item['name'].lower() :
if item['quantity'] != 0 :
print('Pay ', item['price'] , 'at checkout counter.')
item['quantity'] -= 1
else:
print('item out of stock.')
elif choice == '4' :
print('------------------search items------------------')
find_item = input('Enter the item\'s name to search in inventory : ')
for item in items:
if item['name'].lower() == find_item.lower():
print('The item named ' + find_item + ' is displayed below with its details')
print(item)
else:
print('item not found.')
elif choice == '5' :
print('------------------edit items------------------')
item_name = input('Enter the name of the item that you want to edit : ')
for item in items:
if item_name.lower() == item['name'].lower():
print('Here are the current details of ' + item_name)
print(item)
item['name'] = input('Item name : ')
while True:
try:
item['quantity'] = int(input('Item quantity : '))
break
except ValueError:
print('Quantity should only be in digits')
while True:
try:
item['price'] = int(input('Price $ : '))
break
except ValueError:
print('Price should only be in digits')
print('Item has been successfully updated.')
print(item)
else:
print('Item not found')
elif choice == '6' :
print('------------------exited------------------')
break
else:
print('You entered an invalid option')