Day1 购物车

购物车需求:

1.输入薪资

2.选择商品id添加到购物车

3.退出后打印购物车商品

 

print ('hello')
ls = [
    ('IPhone',5800),
    ('Mac Pro',12000),
    ('Bike',800)
]
cart = []
salary = raw_input('please input your salary:')
if salary.isdigit():
    salary = int(salary)
    print 'you can buy this:'
    for item in ls:            # equal for index,item in enumerate(ls):
        print ls.index(item),':',item
    while True:
        code = int(raw_input('input code,add shoppint cart:'))
        cart.append(ls[code])
        salary -= ls[code][1]
        if salary < 0:
            print 'your money is not enough!'
            exit()
        else:
            confirm = raw_input('you have add {0} to cart,current money is {1}.continue(y/n)?'.format(ls[code],salary))
            if confirm.strip() == 'y':
                continue
            else:
                print 'your shopping cart is {buys},your moneys is \033[42m{money}\033[0m'.format(buys=cart,money=salary)
                break
else:
    print 'no valid salary!'

 

posted on 2017-05-08 18:52  feel628  阅读(101)  评论(0)    收藏  举报

导航