commodity={1:["milk",50],2:["oil",40],3:["rice",30],4:["soap",20],5:["orange",10]}
min_price=10000
buy_list=[]
# print(commodity.keys())
salary=int(input("输入工资:"))
for key in commodity.keys():
if commodity[key][1]<min_price:
min_price=commodity[key][1]
# print(min_price)
while True:
print("salary: ",salary)
print("商品列表:")
for i in commodity.items():
print(i)
choice=int(input("购买的商品编号,输入0退出购买:"))
if choice==0:
print("已经购买的商品")
print("------")
break
elif choice in [i for i in commodity.keys()]:
if salary<commodity[choice][1]:
print("薪水不足,购买失败")
continue
print("成功购买商品:",commodity[choice][0])
salary=salary-commodity[choice][1]
buy_list.append(commodity[choice][0])
else:
print("输入错误")
print("已经购买的商品")
print(buy_list)
python 输入
最新推荐文章于 2023-11-04 11:15:03 发布