forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrocerymanagement.py
More file actions
70 lines (62 loc) · 2.3 KB
/
Copy pathGrocerymanagement.py
File metadata and controls
70 lines (62 loc) · 2.3 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
# Simple Grocery Inventory Management
inventory = {}
def add_item():
item_name = input("Enter the name of the item: ").strip().capitalize()
if item_name in inventory:
print(f"{item_name} already exists. Updating quantity.")
inventory[item_name] += int(input("Enter the quantity to add: "))
else:
quantity = int(input("Enter the quantity: "))
price = float(input("Enter the price per unit: "))
inventory[item_name] = {"quantity": quantity, "price": price}
print(f"{item_name} has been added/updated.")
def view_inventory():
if not inventory:
print("The inventory is empty.")
return
print("\nCurrent Inventory:")
print(f"{'Item':<15}{'Quantity':<10}{'Price/Unit':<10}")
print("-" * 35)
for item, details in inventory.items():
print(f"{item:<15}{details['quantity']:<10}{details['price']:<10.2f}")
print()
def update_item():
item_name = input("Enter the name of the item to update: ").strip().capitalize()
if item_name in inventory:
quantity = int(input("Enter the new quantity: "))
price = float(input("Enter the new price per unit: "))
inventory[item_name] = {"quantity": quantity, "price": price}
print(f"{item_name} has been updated.")
else:
print(f"{item_name} does not exist in the inventory.")
def delete_item():
item_name = input("Enter the name of the item to delete: ").strip().capitalize()
if item_name in inventory:
del inventory[item_name]
print(f"{item_name} has been deleted.")
else:
print(f"{item_name} does not exist in the inventory.")
def main():
while True:
print("\nGrocery Inventory Management")
print("1. Add Item")
print("2. View Inventory")
print("3. Update Item")
print("4. Delete Item")
print("5. Exit")
choice = input("Enter your choice: ").strip()
if choice == '1':
add_item()
elif choice == '2':
view_inventory()
elif choice == '3':
update_item()
elif choice == '4':
delete_item()
elif choice == '5':
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()