商品信息管理系统
print("欢迎使用商品管理系统")
infos = []
def add_good():
info = {
}
name = input("名称:")
price = input("价格:")
cla = input("类别:")
info['name'] = name
info['price'] = price
info['cla'] = cla
infos.append(info)
print("商品录入成功!\n")
def find_good():
while True:
print("1、根据商品的名称查找")
print("2、根据商品的价格查找")
print("3、根据商品的类别查找")
print("4、退出查找")
num2 = int(input("请输入功能序号:"))
if num2 == 1:
name2 = input("请输入你要查找的商品名称:")
flag = 0
for i in infos:
if i.get('name') == name2:
print("名称:{}\n价格:{}\n类别:{}\n".format(i.get('name'), i.get('price'), i.get('cla')))
flag = 1
if not flag:
print("查无此商品!")
elif num2 == 2:
price = input("请输入商品的价格:")
flag = 0
for i in infos:
if (i.get('price') == price):
print("名称:{}\n价格:{}\n类别:{}\n".format(i.get('name'), i.get('price'), i.get('cla')))
flag = 1
if not flag:
print("查无此商品!")
elif num2 == 3:
flag = 0
cla = input("请输入要查找的类别:")
for i in infos:
if (i.get('cla') == cla):
print("名称:{}\n价格:{}\n类别:{}\n".format(i.get('name'), i.get('price'), i.get('cla')))
flag = 1
if not flag:
print("查无此商品!")
elif num2 == 4:
break
def change_good():
while True:
print("1、修改商品的价格")
print("2、修改商品的属性")
print("3、退出修改")
num3 = int(input("请输入你要修改的序号:"))
if num3 == 1:
flag = 0
name3 = input("请输入商品的名称:")
for i in infos:
if i.get("name") == name3:
price = int(input("请输入修改后的价格:"))
i["price"] = price
print("更新后的商品信息")
print("名称:{}\n价格:{}\n类别:{}\n".format(i.get('name'), i.get("price"), i.get("cla")))
flag = 1
if not flag:
print("没有你要修改的商品")
elif num3 == 2:
flag = 0
name3 = input("请输入商品的名称:")
for i in infos:
if i.get("name") == name3:
cla = input("请输入修改后的类别:")
i["cla"] = cla
print("更新后的商品信息")
print("名称:{}\n价格:{}\n类别:{}\n".format(i.get('name'), i.get("price"), i.get("cla")))
flag = 1
if not flag:
print("没有你要修改的商品")
elif num3 == 3:
break
def dele_good():
flag = 0
name = input("请输入你要下架的商品名称:")
for i in infos:
if i.get('name') == name:
infos.remove(i)
print("删除成功!")
flag = 1
if not flag:
print("没有找到这个商品的信息!")
def list_goods():
flag = 0
for i in infos:
print("{}\t{}\t{}".format(i.get('name'), i.get('price'), i.get('cla')))
flag = 1
if not flag:
print("商品列表中没有商品信息!")
while True:
print("*************")
print("1、录入商品信息")
print("2、查询商品信息")
print("3、修改商品信息")
print("4、下架某个商品")
print("5、列出所有商品")
print("6、退出管理系统")
print("*************")
num = int(input("请选择功能:"))
if num == 1:
add_good()
elif num == 2:
find_good()
elif num == 3:
change_good()
elif num == 4:
dele_good()
elif num == 5:
list_goods()
elif num == 6:
print("成功退出系统!")
break