-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventry.py
More file actions
73 lines (65 loc) · 2.4 KB
/
Inventry.py
File metadata and controls
73 lines (65 loc) · 2.4 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
# Inventory Management System
# Initialize an empty list to store inventory items
inventory = []
# Function to add an item to the inventory
def add_item(item_name, quantity, price):
item = {
"name": item_name,
"quantity": quantity,
"price": price
}
inventory.append(item)
print(f"Added '{item_name}' to the inventory.")
# Function to view all inventory items
def view_inventory():
if not inventory:
print("Your inventory is empty.")
else:
print("Inventory:")
for i, item in enumerate(inventory, 1):
print(f"{i}. Name: {item['name']}, Quantity: {item['quantity']}, Price: ${item['price']:.2f}")
# Function to update an item in the inventory
def update_item(item_index, new_quantity, new_price):
if 1 <= item_index <= len(inventory):
item = inventory[item_index - 1]
item["quantity"] = new_quantity
item["price"] = new_price
print(f"Updated '{item['name']}' in the inventory.")
else:
print("Invalid item index!")
# Function to delete an item from the inventory
def delete_item(item_index):
if 1 <= item_index <= len(inventory):
deleted_item = inventory.pop(item_index - 1)
print(f"Deleted '{deleted_item['name']}' from the inventory.")
else:
print("Invalid item index!")
# Main program loop
while True:
print("\nInventory Management System")
print("1. Add Item")
print("2. View Inventory")
print("3. Update Item")
print("4. Delete Item")
print("5. Quit")
choice = input("Enter your choice : ")
if choice == "1":
item_name = input("Enter the item name: ")
quantity = int(input("Enter the quantity: "))
price = float(input("Enter the price: "))
add_item(item_name, quantity, price)
elif choice == "2":
view_inventory()
elif choice == "3":
item_index = int(input("Enter the item number to update: "))
new_quantity = int(input("Enter the new quantity: "))
new_price = float(input("Enter the new price: "))
update_item(item_index, new_quantity, new_price)
elif choice == "4":
item_index = int(input("Enter the item number to delete: "))
delete_item(item_index)
elif choice == "5":
print("Exiting the inventory management system. \n Created by Qavi Shaikh")
break
else:
print("Invalid choice. Please select a valid option.")