python简单购物车

#Author:zhou

shopping = [("iphone",5500),("macbook",10000),("knife",15)]
wallet = int(input("请输入你的金额:"))
shopping2 = []
while True:

    for Index,value in enumerate(shopping):
        print("商品编号:{Index}{value}".format(Index=Index,value=value))
    number = input("请输入你想购买的商品编号:Q退出")
    if number.isdigit():
        if int(number) < len(shopping) and int(number) >= 0:
            shopping2.append(shopping[int(number)])
            wallet -= shopping[int(number)][1]
            if wallet < 0:
                print('余额不足,现在的余额是 \033[31;1m%s\033[0m' % (wallet + shopping[int(number)][1]))
                shopping2.pop()
                wallet += shopping[int(number)][1]
                continue
            print('你现在余额是\033[31;1m%s\033[0m,购买的商品是%s' % (wallet, shopping2))
        else:
            print("错误!请输入正确的商品编号")
    elif number == 'Q':
            break
print("你所购买的产品如下")
shopping2.sort()
for p in shopping2:
       print(p)
;