Inventory tracker

syn_goddi_80ad5dcc9d68127

Syn Goddi

Posted on September 8, 2024

Inventory tracker

Inventory dictionary with colors as keys

inventory = {
"White": {},
"Brown": {},
"Coal": {},
"Musket": {},
"Cream": {},
"Eggshell": {},
"Tan": {},
"Terra-tone": {},
"Light Grey": {},
"Red": {},
"Green": {},
"Clay": {}
}

def view_inventory():
"""Displays the inventory of each color."""
for color, items in inventory.items():
print(f"\n{color} Inventory:")
if items:
for item, count in items.items():
print(f" {item}: {count}")
else:
print(" No items in inventory.")

def use_inventory():
"""Allows the user to subtract inventory for a specific color."""
color = input("Enter color: ").capitalize()
if color in inventory:
if inventory[color]:
for item, count in inventory[color].items():
print(f"{item}: {count}")
item_name = input("Enter the item name to subtract from: ").capitalize()
if item_name in inventory[color]:
try:
subtract_count = int(input(f"Enter amount to subtract from {item_name}: "))
inventory[color][item_name] = max(0, inventory[color][item_name] - subtract_count)
print(f"{subtract_count} removed from {item_name}. New count: {inventory[color][item_name]}")
except ValueError:
print("Invalid input. Please enter a number.")
else:
print("Item not found in inventory.")
else:
print(f"No items in {color} inventory.")
else:
print("Color not found.")

def receive_inventory():
"""Allows the user to add inventory to a specific color."""
color = input("Enter color: ").capitalize()
if color in inventory:
if inventory[color]:
for item, count in inventory[color].items():
print(f"{item}: {count}")
item_name = input("Enter the item name to add to: ").capitalize()
if item_name in inventory[color]:
try:
add_count = int(input(f"Enter amount to add to {item_name}: "))
inventory[color][item_name] += add_count
print(f"{add_count} added to {item_name}. New count: {inventory[color][item_name]}")
except ValueError:
print("Invalid input. Please enter a number.")
else:
print("Item not found in inventory.")
else:
print(f"No items in {color} inventory.")
else:
print("Color not found.")

def add_inventory_item():
"""Allows the user to add a new item to a specific color's inventory."""
color = input("Enter color: ").capitalize()
if color in inventory:
item_name = input("Enter the new item name: ").capitalize()
try:
item_count = int(input(f"Enter the starting count for {item_name}: "))
inventory[color][item_name] = item_count
print(f"{item_name} added to {color} with count {item_count}.")
except ValueError:
print("Invalid input. Please enter a number.")
else:
print("Color not found.")

def main_menu():
while True:
print("\n1. View inventory")
print("2. Use inventory")
print("3. Receive inventory")
print("4. Add inventory item")
print("5. Exit")
choice = input("Enter your choice: ")

   if choice == '1':
view_inventory()
elif choice == '2':
use_inventory()
elif choice == '3':
receive_inventory()
elif choice == '4':
add_inventory_item()
elif choice == '5':
print("Exiting program.")
break
else:
print("Invalid choice. Please try again.")
Enter fullscreen mode Exit fullscreen mode




Run the program

if name == "main":
main_menu()

💖 💪 🙅 🚩
syn_goddi_80ad5dcc9d68127
Syn Goddi

Posted on September 8, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024