zoukankan      html  css  js  c++  java
  • 购物车程序

       

    __author__ = 'xitaozi'
    '''
    使用列表实现购物车
    '''
    produce_list = [
        ('Macbook pro 15.4',14288),
        ('Think pad X1 carbon',10000),
        ('HP WASD',7000),
        ('Dell xps 13',8000)
    ]
    
    while True:
        budget = input("请输入购物预算:")
        shopping_list = []
        if budget.isdigit():
            budget = int(budget)
            while True:
                for (item,product) in enumerate(produce_list):
                    print(item,product)
                user_choice = input("选择商品编号,加入购物车。输入字母'Q'退出")
                if user_choice.isdigit():
                    user_choice = int(user_choice)
                    if user_choice < len(produce_list) and user_choice >= 0:
                        p_item = produce_list[user_choice]
                        if p_item[1] <= budget:
                            shopping_list.append(p_item)
                            budget = budget - p_item[1]
                            print("加入%s购物车成功,您的预算余额为:%d。"%(p_item,budget))
                        else:
                            print("您的预算余额为:%d,无法继续购买。"%budget)
                    else:
                        print("商品编号输入错误,请重新输入。")
                elif user_choice == 'Q'or user_choice == 'q':
                    print("--------您的购物车有如下商品--------")
                    for shop_item in shopping_list:
                        print(shop_item)
                    exit()
                else:
                    print("输入错误")
        else:
            print("输入错误,请重新运行程序。")
    

      

  • 相关阅读:
    M-CloneG-DFS-BFS-图
    M-WordB-BFS-DP
    Reverse Linked List II
    OpenCV 第二课 认识图像的存储结构
    Surf特征提取分析
    OpenCV 第一课(安装与配置)
    简单验证码识别(matlab)
    matlab中各种高斯相关函数
    SIFT特征提取分析
    斑点检测(LoG,DoG)(下)
  • 原文地址:https://www.cnblogs.com/xitaozi/p/6091548.html
Copyright © 2011-2022 走看看