-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory_management.py
More file actions
69 lines (60 loc) · 2.17 KB
/
Copy pathinventory_management.py
File metadata and controls
69 lines (60 loc) · 2.17 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
import json
class Item:
def __init__(self, name, quantity, price):
self.name = name
self.quantity = quantity
self.price = price
class InventoryManagementSystem:
def __init__(self):
self.inventory = []
def add_item(self, name, quantity, price):
self.inventory.append(Item(name, quantity, price))
def view_items(self):
if not self.inventory:
print("No items in inventory.")
return
for item in self.inventory:
print(f"Name: {item.name}, Quantity: {item.quantity}, Price: ${item.price:.2f}")
def update_item(self, name, quantity, price):
for item in self.inventory:
if item.name == name:
item.quantity = quantity
item.price = price
print(f"Item {name} updated.")
return
print(f"Item {name} not found in inventory.")
def delete_item(self, name):
self.inventory = [item for item in self.inventory if item.name != name]
print(f"Item {name} deleted.")
def main():
ims = InventoryManagementSystem()
while True:
print("\nInventory Management System:")
print("1. Add Item")
print("2. View Items")
print("3. Update Item")
print("4. Delete Item")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == "1":
name = input("Enter item name: ")
quantity = int(input("Enter item quantity: "))
price = float(input("Enter item price: "))
ims.add_item(name, quantity, price)
elif choice == "2":
ims.view_items()
elif choice == "3":
name = input("Enter item name to update: ")
quantity = int(input("Enter new quantity: "))
price = float(input("Enter new price: "))
ims.update_item(name, quantity, price)
elif choice == "4":
name = input("Enter item name to delete: ")
ims.delete_item(name)
elif choice == "5":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()