码迷,mamicode.com
首页 > 其他好文 > 详细

购物车程序

时间:2018-07-07 20:44:56      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:名称   bsp   ase   and   lease   enum   [1]   pen   code   

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(请输入工资金额)

 

购物车程序

标签:名称   bsp   ase   and   lease   enum   [1]   pen   code   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!