代码练习-购物车

自动加入购物车,推出显示所有购物车

products = [['iphone8', 6888], ["MacPro", 14800], ['小米6', 2499], ['coffee', 31], ['boot', 80], ['Nike Shose', 799]]
goods = []
print('-------------商品列表--------------')

while True :
    for index, i in enumerate(products):
        print('%s     %s             %s' %(index,i[0],i[1]))

    user_change = input('请输入您要购买的商品序号,如果推出请按Q/q:')

    if  user_change.isdigit():

        if int(user_change) > 0 and int(user_change) < len(products):
            goods.append(products[int(user_change)])
        else :
            print('无此商品')
    elif user_change == 'q'  or user_change == 'Q':
        print('您所购买的商品为:')
        for i in goods:
            print(i[0],i[1],)

        break

    else:
        print('请输入正确的商品序号')


猜你喜欢

转载自blog.51cto.com/317487/2165738