#Author:Kevin_hou
#定义产品列表
product_list =[
('HUAWEI',5999),
('Watch',500),
('Nike',800),
('Toyota',200000),
('basketball',500),
('bike',1000),
]
shopping_list =[] #定义购物车列表
salary = input("your salary is...>>>") #首要先输入工资
if salary.isdigit(): #然后工资要是数值
salary =int(salary) #将工资取整,因为产品价格均为整数值
while True: #while True循环语句
for index,item in enumerate(product_list): #for循环语句,用于依次输出产品列表,index指数组下标值,item指具体产品
print(index,item) #输出 0 ('HUAWEI', 5999)
user_choice = input("what do you want buy ?") #输入用户选择的产品,即数组值
if user_choice.isdigit(): #判断如果用户输入的是数字变量
user_choice =int(user_choice) #取整
if user_choice< len(product_list) and user_choice >=0: #如果是数字量,再次判断数字值是否在产品数量区间内
p_item = product_list[user_choice] #将用户选择的产品赋给p_item
if p_item[1] <= salary: #再判断产品价格不大于工资值
shopping_list.append(p_item) #如果不大于,加入购车列表
salary -= p_item[1] #余额=工资-支付的费用
print("Add %s into shopping cart, your current balance is 33[31;1m%s 33[0m" %(p_item,salary)) #输出余额
else:
print(" 33[41;1m your current balance is [%s], you have no enough many to pay...>>>