#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Icing
"""
购物车程序:
1、启动程序后,让用户输入工资,然后打印商品列表
2、允许用户根据商品编号购买商品
3、用户选择商品后,检测余额是否足够,够就直接扣款;不够就提醒
4、可随时退出,退出时,打印已购买的商品和余额
"""
goodlist = [[1,"iphone",5000],
[2,"mac",13999],
[3,'book',56],
[4,'bike',1200],
[5,'pen',23]]
mylist = []
salary = input("Your salary is:")
if salary.isdigit():
mysalary = int(salary)
while True:
a = input("select goods id:")
if a == "q":
print("您已选择退出!")
print(mylist)
else:
goodID = int(a)
# print(len(goodlist))
if goodID > len(goodlist):
print("您输入的商品不存在")
break
for i in goodlist:
print(i)
# mysalary = int(salary)
# print(goodlist[goodID][2])
if mysalary > goodlist[goodID-1][2]:
mysalary = mysalary - int(goodlist[goodID-1][2])
mylist.append(goodlist[goodID-1][1])
print("商品列表:", mylist)
print("余额:\033[31;1m%s\033[0m"%mysalary)
else:
print("Your salary is not enough")
else:
print("请输入正确的工资")