python仓储管理系统代码
时间: 2023-11-09 13:03:37 浏览: 30
以下是一个简单的Python仓储管理系统代码,可以作为参考:
```python
class Item:
def __init__(self, name, quantity):
self.name = name
self.quantity = quantity
class Inventory:
def __init__(self):
self.items = []
def add_item(self, name, quantity):
for item in self.items:
if item.name == name:
item.quantity += quantity
return
new_item = Item(name, quantity)
self.items.append(new_item)
def remove_item(self, name, quantity):
for item in self.items:
if item.name == name:
if item.quantity >= quantity:
item.quantity -= quantity
if item.quantity == 0:
self.items.remove(item)
return
else:
print("Not enough quantity!")
return
print("Item not found!")
def print_inventory(self):
for item in self.items:
print(item.name + ": " + str(item.quantity))
inventory = Inventory()
inventory.add_item("apple", 10)
inventory.add_item("banana", 5)
inventory.print_inventory()
inventory.remove_item("apple", 5)
inventory.print_inventory()
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)