首页 > 其他 > 详细

购物车程序

时间:2018-07-07 19:45:49      阅读:222      评论:0      收藏:0      [点我收藏+]
salary = input(‘please input your monthly salary: ‘)
goods_list = [
    (‘iphone‘, 5000),
    (‘mac pro‘, 12000),
    (‘TV‘, 4500),
    (‘pencel‘, 25)
]
shopping_list = []
if salary.isdigit():
    salary = int(salary)
    while True:
        for index, item in enumerate(goods_list):
            print(‘商品编号:%d, 商品名称:%s, 商品价格:%d‘ % (index, item[0], item[1]))
        choice = input(‘请选择你要的商品:>>‘)
        if choice.isdigit():
            choice = int(choice)
            if choice < len(goods_list) and choice >= 0:
                choice_good = goods_list[choice]
                if choice_good[1] <= salary:
                    shopping_list.append(goods_list[choice])
                    salary = salary - choice_good[1]
                    print(‘你还有余额: %d‘ % salary)
                else:
                    print(‘你的余额仅有:%d啦,不够购买此商品‘%salary)

            else:
                print(‘没有%d的商品编码‘ % choice)
        elif choice == ‘q‘:
            print(‘-----------SHOPPING LIST----------‘)
            for i in shopping_list:
                print(i)
            print(‘你还有余额: %d‘ % salary)
            exit()
        else:
            print("请输入商品编号")

else:
    print(‘请输入工资金额‘)

 

购物车程序

原文:https://www.cnblogs.com/hulala8/p/9277679.html

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