建立一个仓库管理系统python代码
时间: 2023-09-16 18:14:46 浏览: 52
以下是一个简单的仓库管理系统的Python代码示例:
```python
class Item:
def __init__(self, name, price, quantity):
self.name = name
self.price = price
self.quantity = quantity
class Inventory:
def __init__(self):
self.items = []
def add_item(self, item):
self.items.append(item)
def remove_item(self, name):
for item in self.items:
if item.name == name:
self.items.remove(item)
def update_item(self, name, price, quantity):
for item in self.items:
if item.name == name:
item.price = price
item.quantity = quantity
def display_inventory(self):
for item in self.items:
print(f"{item.name} - Price: {item.price} - Quantity: {item.quantity}")
inventory = Inventory()
while True:
print("1. Add item")
print("2. Remove item")
print("3. Update item")
print("4. Display inventory")
print("5. Exit")
choice = int(input("Enter choice: "))
if choice == 1:
name = input("Enter item name: ")
price = float(input("Enter item price: "))
quantity = int(input("Enter item quantity: "))
item = Item(name, price, quantity)
inventory.add_item(item)
print("Item added.")
elif choice == 2:
name = input("Enter item name: ")
inventory.remove_item(name)
print("Item removed.")
elif choice == 3:
name = input("Enter item name: ")
price = float(input("Enter item price: "))
quantity = int(input("Enter item quantity: "))
inventory.update_item(name, price, quantity)
print("Item updated.")
elif choice == 4:
inventory.display_inventory()
elif choice == 5:
break
else:
print("Invalid choice. Try again.")
```
这个简单的程序允许用户添加、删除、更新和显示存货清单。每个存货项都由名称、价格和数量组成。程序使用一个包含所有存货项的列表来存储存货清单。用户可以通过输入数字选择操作。程序还包括一个循环,直到用户选择退出。