首页 > 其他 > 详细

购物车

时间:2019-05-21 23:39:49      阅读:119      评论:0      收藏:0      [点我收藏+]
product_list = [
    (iphone, 5000),
    (mac Pro, 12000),
    (bike, 800),
    (book, 120),
    (watch, 10600),
    (coffee, 20)
]
shopping_list = []
salary = input("input you salary:")
if salary.isdigit():
    salary = int(salary)
    while True:
        # for item in product_list:
        #     print(product_list.index(item), item)
        for index, item in enumerate(product_list):
            print(index, item)
        user_choice = input("请输入想要买的商品序号:")
        if user_choice.isdigit():
            user_choice = int(user_choice)
            if 0 <= user_choice < len(product_list):
                p_item = product_list[user_choice]
                if p_item[1] <= salary:
                    shopping_list.append(p_item)
                    salary -= p_item[1]
                    print("%s is added into your shopping_list,the current balance is \033[31;1m%s\033[0m" % (p_item[0], salary))
                else:
                    print("\033[41;1m余额不足\033[0m")
            else:
                print("\033[41;1m商品不存在,请重新输入\033[0m")

        elif user_choice == q:
            print("--------shopping_list--------")
            for p in shopping_list:
                print(p)
            print("your current salary:",salary)
            exit()
        else:
            print("\033[41;1m invalid input\033[0m")
else:
    print("\033[41;1m invalid input\033[0m")
技术分享图片

 


 

购物车

原文:https://www.cnblogs.com/TY666/p/10903211.html

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