Untitled
unknown
plain_text
2 years ago
2.2 kB
11
Indexable
class Item: def _init_(self, name, price, quantity): self.name = name self.price = price self.quantity = quantity # Create an initial inventory with at least 5 items inventory = [ Item("Item1", 10.99, 50), Item("Item2", 5.99, 30), Item("Item3", 2.49, 100), Item("Item4", 7.99, 20), Item("Item5", 15.49, 10) ] def display_inventory(inventory): print("Inventory:") for item in inventory: print(f"Name: {item.name}, Price: ${item.price:.2f}, Quantity: {item.quantity}") def add_item(inventory): name = input("Enter the name of the new item: ") price = float(input("Enter the price of the new item: ")) quantity = int(input("Enter the quantity of the new item: ")) new_item = Item(name, price, quantity) inventory.append(new_item) print(f"{name} has been added to the inventory.") def update_quantity(inventory): name = input("Enter the name of the item to update: ") for item in inventory: if item.name == name: new_quantity = int(input("Enter the new quantity: ")) item.quantity = new_quantity print(f"Quantity for {name} has been updated to {new_quantity}.") break else: print(f"{name} is not in the inventory.") def remove_item(inventory): name = input("Enter the name of the item to remove: ") for item in inventory: if item.name == name: inventory.remove(item) print(f"{name} has been removed from the inventory.") break else: print(f"{name} is not in the inventory.") while True: print("\nOptions:") print("1. Display Inventory") print("2. Add Item") print("3. Update Quantity") print("4. Remove Item") print("5. Exit") choice = input("Enter your choice: ") if choice == '1': display_inventory(inventory) elif choice == '2': add_item(inventory) elif choice == '3': update_quantity(inventory) elif choice == '4': remove_item(inventory) elif choice == '5': break else: print("Invalid choice. Please try again.") print("Thank you for using the inventory management system!")
Editor is loading...