zoukankan      html  css  js  c++  java
  • 购物车程序示例,支持显示购买商品数量

    goods_list = [("IphoneX", 9000), ("Tesla", 700000), ("Python book", 55),
          ("coffee", 35), ("Computer", 6999), ("Bitcoin", 67000), ("Food", 20), ("TV", 5000)]
    shopping_car = []
    cost = 0.0


    print("Welcome to the shopping market,here is your shopping car.")
    print("You can enter 'q' to quit at anytime.")
    print("You can enter 'p' to purchase the goods you buy.")
    print("You can enter 's' to show your shopping car.")
    print("You can enter 'r' to show the goods list again.")
    print("Here are the goods list:")
    for i, v in enumerate(goods_list, 1):
      print(i, ">>>>>>>>>>>>>>>>", v)

    saving = input("Please input your salary: ")
    if saving.isdigit():
      saving = float(saving)
      while True:
        choose = input("Please enter the goods NO. you want to buy: ")
        if choose.isdigit():
          choose = int(choose)

          if choose > 0 and choose <= len(goods_list):

            if goods_list[choose - 1][1] < saving:
              shopping_car.append(goods_list[choose - 1])
              cost += goods_list[choose - 1][1]
              saving -= cost
              print("Adding %s in your shopping car,it costs %f CNY" %
                (goods_list[choose - 1][0], goods_list[choose - 1][1]))
            else:
              print("Not enough money to buy this goods.")
          else:
            print("Invalid choosen range.")
        elif choose == "q":
          print("Thanks for coming! See you next time!")
          break
        elif choose == "purchase":
          print("Here is your shopping car".center(70, "-"))
          shopping_car_set = set(shopping_car)
          for goods in shopping_car_set:
            print(goods, "-------------NO:", str(shopping_car.count(goods)),
              "----------COSTS:", goods[1] * shopping_car.count(goods))
          print("Total cost: %f CNY" % cost)
          print("Your saving is now %f CNY" % saving)
          break
        elif choose == "r":
          for i, v in enumerate(goods_list, 1):
            print(i, ">>>>>>>>>>>>>>>>", v)
        elif choose == "s":
          for i in shopping_car:
            print(i)
        else:
          print("Invalid Input.Try again :-)")


     

  • 相关阅读:
    kde下sudo出现cannot connect to xserver解决方法
    windows版本的Emacs 无法显示图片的解决方法
    Ubuntu12.04安装VMwareWorkstation8.0.2591240.x86_64
    在Emacs调试JAVA程序,使用GUD模式
    配置SQL Server Session方法(1)
    C#泛型列表List<T>基本用法总结
    VC++的MFC中 获取选中静态文本的内容
    用P3P header解决IE下iframe跨域访问时候session丢失的问题
    ROW_NUMBER()用法(转)
    VC 中与字符串相关的宏 _T、TEXT,_TEXT、L 的作用
  • 原文地址:https://www.cnblogs.com/fengbo1113/p/7905357.html
Copyright © 2011-2022 走看看