像商城和超市这样的地方,都需要有自己的库房,并且库房商品的库存变化有专人记录,这样才能保证商城和超市正常运转。 本例要求编写一个程序,模拟库存管理系统。该系统主要包括系统首页、商品入库、商品显示和删除商品功能。每个功能的具体要求如下: (1)系统的首页:用于显示系统所有的操作,并且可以选择使用某一个功能。 (2)商品入库功能:首先提示是否要录入商品,根据用户输入的信息判断是否需要录入商品。如果需要录入商品,则需要用户输入商品的名称、颜色、价格和数量等信息。录入完成后,提示商品录入成功并打印所有商品。如果不
时间: 2023-12-10 10:37:28 浏览: 41
需要录入商品,则直接返回系统首页。
(3)商品显示功能:用户在首页选择该功能后,系统需要打印出所有商品的名称、颜色、价格和数量等信息。
(4)删除商品功能:用户在首页选择该功能后,系统需要提示输入要删除的商品名称,根据用户输入的商品名称进行删除操作,并且提示删除成功。如果要删除的商品不存在,则提示商品不存在。
下面是一个示例程序,可以帮助你更好地理解库存管理系统的实现过程:
```
# 定义商品列表
products = []
# 系统首页
def home():
print("欢迎使用库存管理系统")
print("1. 商品入库")
print("2. 商品显示")
print("3. 删除商品")
print("0. 退出系统")
# 商品入库功能
def add_product():
choice = input("是否需要录入商品?(Y/N)")
if choice.upper() == "Y":
name = input("请输入商品名称:")
color = input("请输入商品颜色:")
price = input("请输入商品价格:")
quantity = input("请输入商品数量:")
products.append({"name": name, "color": color, "price": price, "quantity": quantity})
print("商品录入成功!")
print_products()
elif choice.upper() == "N":
home()
else:
print("输入错误,请重新输入!")
add_product()
# 商品显示功能
def print_products():
print("商品列表:")
for product in products:
print("-" * 30)
print("名称:", product["name"])
print("颜色:", product["color"])
print("价格:", product["price"])
print("数量:", product["quantity"])
# 删除商品功能
def delete_product():
name = input("请输入要删除的商品名称:")
for product in products:
if product["name"] == name:
products.remove(product)
print("删除成功!")
print_products()
return
print("商品不存在!")
# 主程序
while True:
home()
choice = input("请选择功能:")
if choice == "1":
add_product()
elif choice == "2":
print_products()
elif choice == "3":
delete_product()
elif choice == "0":
print("谢谢使用,再见!")
break
else:
print("输入错误,请重新输入!")
```
这个程序可以实现库存管理系统的基本功能,你可以根据实际需求进行修改和扩展。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)