python3 购物车 增改查终极版~

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

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

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

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

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

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

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

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

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

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

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


购物车终极版~

 #!usr/bin/env/ python
# -*- coding:utf-8 -*-
# Author: XiaoFeng goods = [{"name": "铅笔", "price": 2},
{"name": "橡皮", "price": 1},
{"name": "尺子", "price": 3}]
shopping_car = {}
total = 0
print("\033[31;1mWelcome to XiaoXiao's store!\033[0m".center(70, "*"))
while 1:
print("-" * 59)
for index, i in enumerate(goods):
print("商品名:{} {}\t价格:{}元".format(index + 1, i["name"], i["price"]))
choice = input("请输入您的选择(a:添加, d:调整, c: 查看购物车 q: 结算):").strip()
if choice.lower() == "a":
while 1:
order = input("请输入商品编号(b:返回):").strip()
if order.isdigit():
order = int(order)
if 0 < order <= len(goods):
while 1:
num = input("请输入要购买的数量(b:返回):").strip()
if num.isdigit():
num = int(num)
if goods[order - 1]["name"] in shopping_car:
shopping_car[goods[order - 1]["name"]]["num"] = \
shopping_car[goods[order - 1]["name"]]["num"] + num
break
else:
shopping_car[goods[order - 1]["name"]] = \
{"price": goods[order - 1]["price"], "num": num}
break
elif num.lower() == "b":
break
else:
print("请输入数字!")
else:
print("请输入显示范围内的序号!")
elif order.lower() == "b":
break
else:
print("请输入选择序号!")
elif choice.lower() == "d":
while 1:
order_1 = input("请输入想要调整的商品号(b:返回):").strip()
if order_1.isdigit():
order_1 = int(order_1)
if goods[order_1 - 1]["name"] in shopping_car:
while 1:
num_1 = input("请输入想要调整的数量(b:返回)").strip()
if num_1.isdigit():
num_1 = int(num_1)
if num_1 >= 0:
shopping_car[goods[order_1 - 1]["name"]]["num"] = num_1
break
elif num_1 < 0:
print("请别乱来,谢谢")
else:
print("请输入正确的数字!")
elif num_1.lower() == "b":
break
else:
print("请输入数字或选择返回b!")
else:
print("您还没有选购此商品,赶快添加吧~")
elif order_1.lower() == "b":
break
else:
print("请输入有效编号") elif choice.lower() == "c":
total = 0
if shopping_car:
print("\033[40;1m购物车\033[0m".center(50, "-"))
for k, v in shopping_car.items():
print("商品名:{}\t价格:{}元\t\t数量:{}个".format(k, v["price"], v["num"]))
total += v["price"] * v["num"]
print("总计:", total, "元")
else:
print("购物车为空哦,快快选购吧~") elif choice.lower() == "q":
account = input("一共是%d元,现金还是扫码? 嘻嘻!)" % total).strip()
if account.isdigit():
account = int(account)
if account >= total:
print("付款%d元,收您%d元,找零%d元,谢谢惠顾,欢迎下次光临~!" % (account, total, account - total))
break
else:
print("您的余额不足哦,叫媳妇儿来付钱吧~")
else:
print("请刷卡,别开玩笑,给钱或者把东西留下,或者打电话叫你媳妇儿来!")
else:
print("请输入正确操作!")
上一篇:JAVA二维数组的复制


下一篇:Error creating bean with name 'testController': Injection of resource dependencies failed;