salary=int(input("请输入你的工资额度:"))
goodsList=[[‘Sony彩电‘,3888],[‘Apple电脑‘,8999],[‘炒锅‘,199],["Iphone6",3888],["茶杯",77]]
changGoodList=[]
i=1
print("你输入的商品如下:")
for good in goodsList:
print("%d---%s----%d"%(i,good[0],good[1]))
i+=1
flag=True
while flag:
changGoodNumber = int(input("请选择你要购买的商品序号:"))
if changGoodNumber<=len(goodsList):
if int(salary)-goodsList[changGoodNumber-1][1]>=0:
print("购买成功,您购买的商品为%s"%(goodsList[changGoodNumber-1][0]))
changGoodList.append(goodsList[changGoodNumber - 1][0])
salary=salary-int(goodsList[changGoodNumber-1][1])
print("你的工资余额为%d元"%salary)
else:
print("余额不足,无法购买,程序退出")
flag=False
else:
print("无此商品,请重新选择")
原文地址:http://blog.51cto.com/xpqinqun/2103888