zoukankan      html  css  js  c++  java
  • python3 购物车 增改查终极版~

    还是先来条NLP再说,快没了,以后想抄还没有。。。

    十一,没有挫败,只有回应讯息

      “挫败”只是指出过去的做法得不到预期的效果,是给我们需要改变的信号。

      “挫败”只是在事情画上句号时才能用上,欲想事情解决,即是事情仍会继续下去,这二字便不适用。

      “挫败”是指过去的事,“怎样改变做法”是指向未来。

      “挫败“是过去的经验,而经验是让我们提升自我的垫脚石,因为经验是能力的基础,而能力是自信的基础。

      每次”挫败“,都只不过是学习过程里修正行动的其中一步。

      人身里所有的学习,都是经由不断修正而达致完善。

      想要成功,首先要相信有成功的可能。

      每次的”挫败“带来的教训掌握了,每次便都成了学习。

      自信不足的人,潜意识总是在找”不用干下去的“借口,”挫败“二字便很容易冒出来。


    购物车终极版~

     1 #!usr/bin/env/ python
     2 # -*- coding:utf-8 -*-
     3 # Author: XiaoFeng
     4 
     5 goods = [{"name": "铅笔", "price": 2},
     6          {"name": "橡皮", "price": 1},
     7          {"name": "尺子", "price": 3}]
     8 shopping_car = {}
     9 total = 0
    10 print("33[31;1mWelcome to XiaoXiao's store!33[0m".center(70, "*"))
    11 while 1:
    12     print("-" * 59)
    13     for index, i in enumerate(goods):
    14         print("商品名:{} {}	价格:{}元".format(index + 1, i["name"], i["price"]))
    15     choice = input("请输入您的选择(a:添加, d:调整, c: 查看购物车 q: 结算):").strip()
    16     if choice.lower() == "a":
    17         while 1:
    18             order = input("请输入商品编号(b:返回):").strip()
    19             if order.isdigit():
    20                 order = int(order)
    21                 if 0 < order <= len(goods):
    22                     while 1:
    23                         num = input("请输入要购买的数量(b:返回):").strip()
    24                         if num.isdigit():
    25                             num = int(num)
    26                             if goods[order - 1]["name"] in shopping_car:
    27                                 shopping_car[goods[order - 1]["name"]]["num"] = 
    28                                     shopping_car[goods[order - 1]["name"]]["num"] + num
    29                                 break
    30                             else:
    31                                 shopping_car[goods[order - 1]["name"]] = 
    32                                     {"price": goods[order - 1]["price"], "num": num}
    33                                 break
    34                         elif num.lower() == "b":
    35                             break
    36                         else:
    37                             print("请输入数字!")
    38                 else:
    39                     print("请输入显示范围内的序号!")
    40             elif order.lower() == "b":
    41                 break
    42             else:
    43                 print("请输入选择序号!")
    44     elif choice.lower() == "d":
    45         while 1:
    46             order_1 = input("请输入想要调整的商品号(b:返回):").strip()
    47             if order_1.isdigit():
    48                 order_1 = int(order_1)
    49                 if goods[order_1 - 1]["name"] in shopping_car:
    50                     while 1:
    51                         num_1 = input("请输入想要调整的数量(b:返回)").strip()
    52                         if num_1.isdigit():
    53                             num_1 = int(num_1)
    54                             if num_1 >= 0:
    55                                 shopping_car[goods[order_1 - 1]["name"]]["num"] = num_1
    56                                 break
    57                             elif num_1 < 0:
    58                                 print("请别乱来,谢谢")
    59                             else:
    60                                 print("请输入正确的数字!")
    61                         elif num_1.lower() == "b":
    62                             break
    63                         else:
    64                             print("请输入数字或选择返回b!")
    65                 else:
    66                     print("您还没有选购此商品,赶快添加吧~")
    67             elif order_1.lower() == "b":
    68                 break
    69             else:
    70                 print("请输入有效编号")
    71 
    72     elif choice.lower() == "c":
    73         total = 0
    74         if shopping_car:
    75             print("33[40;1m购物车33[0m".center(50, "-"))
    76             for k, v in shopping_car.items():
    77                 print("商品名:{}	价格:{}元		数量:{}个".format(k, v["price"], v["num"]))
    78                 total += v["price"] * v["num"]
    79             print("总计:", total, "")
    80         else:
    81             print("购物车为空哦,快快选购吧~")
    82 
    83     elif choice.lower() == "q":
    84         account = input("一共是%d元,现金还是扫码? 嘻嘻!)" % total).strip()
    85         if account.isdigit():
    86             account = int(account)
    87             if account >= total:
    88                 print("付款%d元,收您%d元,找零%d元,谢谢惠顾,欢迎下次光临~!" % (account, total, account - total))
    89                 break
    90             else:
    91                 print("您的余额不足哦,叫媳妇儿来付钱吧~")
    92         else:
    93             print("请刷卡,别开玩笑,给钱或者把东西留下,或者打电话叫你媳妇儿来!")
    94     else:
    95         print("请输入正确操作!")
  • 相关阅读:
    迭代器
    闭包函数与装饰器
    pyhton的函数
    文件处理
    Python2和Python3编码的区别
    hdu5080:几何+polya计数(鞍山区域赛K题)
    hdu1695:数论+容斥
    HDU3564 --- Another LIS (线段树维护最值问题)
    hdu1521:排列组合---指数型母函数
    poj1014:母函数+优化
  • 原文地址:https://www.cnblogs.com/xf1262048067/p/10695404.html
Copyright © 2011-2022 走看看