#!/usr/bin/env python
#-*-coding=utf-8 -*-
#AUTHOR:duwentao

product_list = [
    ('Iphone',5000),
    ('book',10),
    ('watch',10600),
    ('bike',800),
]

shopping_list=[]

#判断工资是否为数字
salary = input("请输入你的工资:")
if salary.isdigit():
    salary = int(salary)

while True:
    for item in product_list:
        print (product_list.index(item),item)

    user_choice = input('请输入你要购买的商品号:')
    if user_choice.isdigit():
        user_choice = int(user_choice)

        if user_choice >= 0 and user_choice < len(product_list):
            p_item = product_list[user_choice]

            if p_item[1] > salary:
                print('余额不足')
            else:
                shopping_list.append(item)
                salary  -=  p_item[1]
                print('你已经购买了%s,您的余额为%s' %(item,salary))

        else:
            print('你购买的商品不存在')
    elif user_choice == 'q':
        print ('----shopping list----')
        for p in shopping_list:
            print(p)
        print('你的余额为',salary)
        exit()


    else:
        print ("输入有误,请重新编号")
        print ("正在退出")
        exit()