-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinventory_management_sys.py
More file actions
130 lines (111 loc) · 3.89 KB
/
inventory_management_sys.py
File metadata and controls
130 lines (111 loc) · 3.89 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
121
122
123
124
125
126
127
128
129
130
# Inventory Management System
# Data Structures
inventory = [] # List to hold tuples of items
categories = set() # Set to hold unique categories
inventory_dict = {} # Dictionary to manage inventory by item names
# Function to display the menu
def display_menu():
print("\nInventory Management System")
print("-" * 30)
print("1. Add an Item")
print("2. View All Items")
print("3. Search Item by Name")
print("4. Update Item Quantity")
print("5. View Items by Category")
print("6. Exit")
# Add an item to the inventory
def add_item():
item_name = input("Enter Item Name: ").strip()
if item_name in inventory_dict:
print("❗ This item already exists in the inventory.")
return
category = input("Enter Item Category: ").strip()
price = float(input("Enter Item Price: "))
quantity = int(input("Enter Item Quantity: "))
# Create a tuple for the item
item = (item_name, category, price, quantity)
# Add to list and dictionary
inventory.append(item)
inventory_dict[item_name] = {"Category": category, "Price": price, "Quantity": quantity}
# Add category to set
categories.add(category)
print("✅ Item added successfully!")
# View all items
def view_items():
if not inventory:
print("❗ Inventory is empty.")
return
print("\nAll Items:")
print("-" * 50)
for item in inventory:
print(
f"Name: {item[0]}, Category: {item[1]}, Price: {item[2]:.2f}, Quantity: {item[3]}"
)
# Search for an item by name
def search_item():
item_name = input("Enter Item Name to search: ").strip()
if item_name in inventory_dict:
print("\nItem Details:")
for key, value in inventory_dict[item_name].items():
print(f"{key}: {value}")
else:
print("❌ Item not found.")
# Update item quantity
def update_quantity():
item_name = input("Enter Item Name to update quantity: ").strip()
if item_name in inventory_dict:
new_quantity = int(input("Enter New Quantity: "))
inventory_dict[item_name]["Quantity"] = new_quantity
# Update in the inventory list
for i, item in enumerate(inventory):
if item[0] == item_name:
inventory[i] = (
item_name,
inventory_dict[item_name]["Category"],
inventory_dict[item_name]["Price"],
new_quantity,
)
print("✅ Quantity updated successfully!")
else:
print("❌ Item not found.")
# View items by category
def view_by_category():
if not categories:
print("❗ No categories available.")
return
print("\nAvailable Categories:", ", ".join(categories))
selected_category = input("Enter a category to view items: ").strip()
print(f"\nItems in Category: {selected_category}")
print("-" * 50)
found = False
for item in inventory:
if item[1] == selected_category:
print(
f"Name: {item[0]}, Price: {item[2]:.2f}, Quantity: {item[3]}"
)
found = True
if not found:
print("❌ No items found in this category.")
# Main function
def main():
while True:
display_menu()
choice = input("Enter your choice: ")
if choice == "1":
add_item()
elif choice == "2":
view_items()
elif choice == "3":
search_item()
elif choice == "4":
update_quantity()
elif choice == "5":
view_by_category()
elif choice == "6":
print("👋 Exiting Inventory Management System. Goodbye!")
break
else:
print("❌ Invalid choice. Please try again.")
# Entry point
if __name__ == "__main__":
main()