price = [7500,8000,32,80,1500]
name = ["iphone x","mac book","coffee","book","bike"]
thing = [0,0,0,0,0]
msg_1 = '''
---------------------
1.iphone x 7500
2.mac book 8000
3.coffee 32
4.book 80
5.bike 1500
---------------------
'''
print(msg_1)
salary = int(input("salary:"))
balance = salary
while True:
a = input("请输入您要购买的商品序号(离开请按[y]):")
if a == "y" or a == "Y":
break
else:
a = int(a)
if a > 5 or a < 1:
print("请输入正确序号")
continue
elif balance < price[a-1]:
print("余额不足",balance-price[a-1])
else:
print("已加入 %s 到购物车"%name[a-1])
balance -= price[a-1]
print("当前余额:",balance)
thing[a-1] += 1
print("您已购买如下产品:")
for i in range(5):
if thing[i] >= 1:
print("%s * %d %d"%(name[i],thing[i],thing[i]*price[i]))
else:
print("您的余额为:",balance)
product = [
("iphone x",7500),
("mac book",8000),
("coffee",32),
("book",80),
("bike",1500)
]
thing = [0,0,0,0,0]
msg_1 = '''
---------------------
1.iphone x 7500
2.mac book 8000
3.coffee 32
4.book 80
5.bike 1500
---------------------
'''
print(msg_1)
salary = int(input("salary:"))
balance = salary
while True:
a = input("请输入您要购买的商品序号(离开请按[y]):")
if a == "y" or a == "Y":
break
elif a.isdigit():
a = int(a)
if a > 5 or a < 1:
print("请输入正确序号!!!")
continue
elif balance < product[a-1][1]:
print("余额不足",balance-product[a-1][1])
else:
print("已加入 %s 到购物车" % product[a-1][0])
balance -= product[a-1][1]
print("当前余额:", balance)
thing[a-1] += 1
else:
print("请输入正确序号!!!")
print("您已购买如下产品:")
for i in range(5):
if thing[i] >= 1:
print("%s * %d %d"%(product[i][0],thing[i],product[i][1]))
else:
print("您的余额为:",balance)