商品库存管理系统python
时间: 2023-12-29 07:26:38 浏览: 48
以下是一个简单的商品库存管理系统的Python代码示例:
```python
class Product:
def __init__(self):
self.name = input('请输入商品名称:')
self.price = float(input('请输入商品价格:'))
self.index = input('请输入商品编码:')
self.number = int(input('请输入商品数量:'))
def __str__(self):
return '商品名称:{},商品价格:{},数量:{},商品编码:{}'.format(self.name, self.price, self.number, self.index)
# 创建商品列表
products = []
# 添加商品
def add_product():
product = Product()
products.append(product)
print('商品添加成功!')
# 查看商品列表
def view_products():
if len(products) == 0:
print('商品列表为空!')
else:
for product in products:
print(product)
# 删除商品
def delete_product():
index = input('请输入要删除的商品编码:')
for product in products:
if product.index == index:
products.remove(product)
print('商品删除成功!')
return
print('未找到该商品!')
# 修改商品数量
def modify_quantity():
index = input('请输入要修改数量的商品编码:')
for product in products:
if product.index == index:
new_quantity = int(input('请输入新的商品数量:'))
product.number = new_quantity
print('商品数量修改成功!')
return
print('未找到该商品!')
# 主菜单
def main_menu():
while True:
print('1. 添加商品')
print('2. 查看商品列表')
print('3. 删除商品')
print('4. 修改商品数量')
print('5. 退出')
choice = input('请输入您的选择:')
if choice == '1':
add_product()
elif choice == '2':
view_products()
elif choice == '3':
delete_product()
elif choice == '4':
modify_quantity()
elif choice == '5':
break
else:
print('无效的选择,请重新输入!')
# 运行主菜单
main_menu()
```
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)