__Author__ = "MDJ"
#购物车程序
#1、启动程序后,让用户输入工资,然后打印商品列表
#2、允许用户根据商品编号购买商品
#3、用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
#4、可随时退出,退出时,打印已购买商品和余额
salary = int(input("please input your salary:"))
goods = [["Foam",300],["Soap",250],["Mask",600],["SPA",100]]
buygoods = []
num = 0
num1 = 0
count = 0
while salary >= 0 :
while num in range(0,4):
print("序号",num,"、",goods[num][0],"人民币:",goods[num][1])
num += 1
buy = input("请输入要购买的商品序号(输入q退出并结算):")
if buy == "q":
while num1 in range(0,count):
print("已购买:",goods[buygoods[num1]][0],goods[buygoods[num1]][1])
num1 += 1
print("余额:",salary)
break
else:
buy = int(buy)
if salary - goods[buy][1] >= 0:
count += 1
salary = salary - int(goods[buy][1])
buygoods.append(buy)
print("购买成功,余额:",salary)
else:
print("余额不足:购买需要",int(goods[buy][1])," 所剩余额:",salary)