首页 > 其他 > 详细

综合练习[购物车]

时间:2018-06-17 22:59:14      阅读:207      评论:0      收藏:0      [点我收藏+]
product_list = [
    (‘Mac‘, 9000),
    (‘kindle‘, 800),
    (‘tesla‘, 900000),
    (‘python book‘, 105),
    (‘bike‘, 2000)
]

saving = input(‘please input your saving:‘)
shopping_car = []

if saving.isdigit():
    saving = int(saving)
    while True:

        for i,v in enumerate(product_list,1):
            print(i,v)
        choice = input(‘选择购买商品编号[退出:q]:‘)

        if choice.isdigit():
            choice = int(choice)
            if choice > 0 and choice <= len(product_list):
                p_item = product_list[choice-1]
                if p_item[1] < saving:
                    saving -= p_item[1]
                    shopping_car.append(p_item)
                else:
                    print(‘余额不足, 还剩%s‘%saving)
                print(p_item)
            else:
                print(‘编码不存在‘)

        elif choice == ‘q‘:
            print(‘------您已经购买如下商品------‘)
            for i in shopping_car:
                print(i)
            print(‘您还剩%s元钱‘%saving)
            break

        else:
            print("invalid input")

 

综合练习[购物车]

原文:https://www.cnblogs.com/evatan123/p/9193860.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!