-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
117 lines (92 loc) · 3.57 KB
/
menu.py
File metadata and controls
117 lines (92 loc) · 3.57 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
from inventory_manage_system import product
class inventory:
def __init__(self):
self.products = {}
self.total_sales = 0.0
def run(self):
import sys
while True:
print('====inventory menu ===')
print('1: add product/update product')
print('2: view product')
print('3: purchase product')
print('4: view total sales')
print('5: exit')
option = input('choose an option: ')
if option == '1':
self.add_product()
elif option == '2':
self.view_product()
elif option =='3':
self.purchase_product()
elif option == '4':
self.view_total_sales()
elif option == '5':
print('thanks for visiting')
sys.exit()
else:
print('invalid option')
def add_product(self):
product_name = input('enter product name: ')
if not product_name:
print('product_name can not be empty')
return False
update = product_name in self.products
if update:
print(f'{product_name} already exist')
update_choice = input('Do you want to update this product? (yes/no): ')
if update_choice != 'yes':
print('Update cancelled.')
return False
try:
price = (input('enter product price: '))
if not price:
print('price value must be entered')
return False
price = float(price)
if price <= 0:
print('price must be greater than zero')
return False
quantity = (input('enter product quantity: '))
if not quantity:
print('quantity value must be entered')
return False
quantity = float(quantity)
if quantity <= 0:
print('quantity must be greater than zero')
return False
if update:
self.products[product_name].quantity_in_stock += quantity
self.products[product_name].price = price
print(f'Product {product_name} updated successfully')
else:
self.products[product_name] = product(product_name, price, quantity)
print('product added succesfully')
return True
except ValueError:
print('enter a valid number')
return False
def view_product(self):
if not self.products:
print("No products in stock.")
return
print("\nAvailable products:")
for item in self.products.values():
print(f"{item.product_name} - Price: {item.price}, Stock: {item.quantity_in_stock}")
def get_product(self, product_name):
if product_name in self.products:
return self.products[product_name]
else:
print(f'{product_name} not found in inventory')
return
def purchase_product(self):
product_name = input('enter product name: ')
product_item = self.get_product(product_name)
if not product_item:
return
quantity = float(input('enter quantity to purchase: '))
total_price = product_item.purchase_product(quantity)
if total_price is not None:
self.total_sales += total_price
def view_total_sales(self):
print(f'total sales: ${self.total_sales:.2f}')