salary = 5000
i = 1
d = {"iphones": 5800, "mac book": 9000, "coffee": 32, "python book": 80, "bicycle": 1500}
for k,v in d.items():
print("{0}、{1} 价格: {2}".format(i, k, v))
i += 1
m = 1
l = []
ll = []
for k in d.keys():
l.append(k)
while True:
n = input("\n\n请输入要买的商品序号(按'q'直接退出):")
if n == 'q':
print("您已经购买了如下商品:")
for i in ll:
print("\t\t\t{0}".format(i))
print("账户余额为:{0}元\n欢迎下次光临!".format(salary))
break
else:
n = int(n)
n -= 1
if salary < d.get(l[n]):
n = int(n)
x = d.get(l[n])-salary
print("\t\t余额不足,还差{0}元".format(x))
else:
salary=salary-d.get(l[n])
ll.append("{0}: {1}元".format(l[n],str(d.get(l[n]))))
print("\t\t购买成功,当前余额{0}元".format(salary))