flag = True # 登陆功能 def login(): global flag n = 0 with open("用户信息", "r", encoding="utf-8") as f: while n < 3: user_input_name = input("请输入您的用户名:").strip() user_input_pwd = input("请输入您的密码:").strip() for line in f : new_line = line.strip().split(" ") if user_input_name == new_line[0] and user_input_pwd == new_line[1]: print("登陆成功") flag = False break else: print("用户名或密码错误,请重新输入:") n += 1 continue break shopping() # 注册功能 def register(): # 先读再写入 with open("用户信息", "r+", encoding="utf-8") as f: while 1: user_name = input("请输入您要注册的用户名:").strip() user_password = input(("请输入您的密码:").strip()) for line in f: new_line = line.strip().split(" ") if user_name == new_line[0]: print("用户名已存在,请重新输入:") break else: f.write("\n"+user_name+" "+user_password) print("注册成功") break # 购物功能 def shopping(): global flag if flag == False: #判断是否登陆 product_list = [{"name": "电脑", "price": 1999}, {"name": "鼠标", "price": 500}, {"name": "键盘", "price": 999}, {"name": "低音炮", "price": 2222}, {"name": "硬盘", "price": 666} ] shopping_car = {} flag = True while flag: # 用户先给自己的账户充钱 user_account = input("please input your money:").strip() # 判断输入是否合法 if user_account.isdigit(): user_account = int(user_account) break else: print("invalid input") while flag: for i, v in enumerate(product_list): print("{}\t{}\t{}".format(i + 1, v["name"], v["price"])) # 用户输入自己想要的商品编号 user_choice = input("请选择商品编号[exit:q or Q,Shopping settlement:n or N]: ").strip() # 判断输入是否合法 if user_choice.isdigit(): user_choice = int(user_choice) if user_choice > 0 and user_choice < len(product_list)+1: # 将购买得商品放入购物车 if user_choice not in shopping_car: shopping_car[user_choice] = {"name": product_list[user_choice - 1]["name"], "price": product_list[user_choice - 1]["price"], "account": 1 } else: shopping_car[user_choice]["account"] += 1 print( "商品:{},价格:{},已添加到购物车".format(shopping_car[user_choice]["name"], shopping_car[user_choice]["price"])) else: print("输入有误,请重新输入:") # 另一种情况,退出,直接退出程序即可 elif user_choice in ["q", "Q"]: flag = False print("欢迎下次光临") break # 结算情况 elif user_choice in ["n", "N"]: # 展示给顾客自己买的商品,进行购物车得遍历 print("您想要购买的商品如下:") for id, value in shopping_car.items(): print("{}.{}\t单价:{}\t数量{}".format(id, value["name"], value["price"], value["account"])) # 计算一下自己的账户的钱是否够支付买的东西,进行个循环,直到可以购买 while True: sum = 0 # 计算购物费用,遍历price for id, value in shopping_car.items(): sum += value["price"] * value["account"] # 钱够的话直接购买 if user_account >= sum: user_balance = user_account - sum print("您已经成功购买下述商品,", f"您本次消费{sum}元,账户余额{user_balance}元,", "欢迎下次光临") for id, value in shopping_car.items(): print("{}.{}\t单价:{}\t数量:{}".format(id, value["name"], value["price"], value["account"])) flag = False break # 余额不足的情况 else: print("但是您的余额不足,请删除一些商品再结算") # 同上,就是进行合法性判断和将选中的购物车商品删除 user_choice_2 = input("请选择你要删除的商品的编号:").strip() if user_choice_2.isdigit(): user_choice_2 = int(user_choice_2) if user_choice_2 in shopping_car: shopping_car[user_choice_2]["account"] -= 1 if not shopping_car[user_choice_2]["account"]: sum -= int(shopping_car[user_choice_2]["price"]) del shopping_car[user_choice_2] else: print("输入有误") else: print("请输入商品编号") else: print("输入有误,请重新输入:") else: print("您还没有登陆,请先登陆") login() # 刚开始展示给用户的内容 def show(): str = "欢迎进入购物系统" print(str.center(20,"=")) print("1、注册\n" "2、登陆\n" "3、购物\n" "4、退出") # 程序启动 def start(): while True: show() user_choice = input("请输入您的选择:").strip() if user_choice == "1": register() elif user_choice == "2": login() break elif user_choice == "3": shopping() break elif user_choice == "4": break else: print("输入有误,请重新输入:") start()
一、监听器作用:使用 watch 观察和响应 Vue 实例上的数据变动适用场景:当需要在数据变化时执行异步或开销较大的操作时百度实时搜索案例:<div id="app"> 请输入查询的内容:<input type="text" v-model="val"> <ul id="outputBox"> &...
最近有的站长发现打开网站一直停在加载fonts.useso.com中,fonts.useso.com本来是360网站卫士CDN加速的字体服务,但是现在已经停止服务了!但是谷歌的字体服务已经能使用了,其实早在15年初google就在北京设置了服务器,ping fonts.useso.com 也可以发现,ip为203.208.40.136,地址是北京电信海...
注解 作用 @Controller 处理http请求 @RestController Spring4之后新加的注解,作用和原来的@ResponseBody配合@Controller相同。用于返回Json @PathVariable 获取url中的参数 @RequestParam 获取请求参数的值 @RequestMapping
本文表格、实例均来自数据库大神 @孟勃荣 的分享。谈到事务隔离级别,开发同学都能说个八九不离十。脏读、不可重复读、RC、RR...这些常见术语也大概知道是什么意思。但是做技术,严谨和细致很重要。如果对事务隔离级别的认识,仅仅停留在大概知道的程度,数据库内核研发者可能开发出令用户费解的隔离级别表现,业务研发者可能从数据库中查出与预期不符的结果。那么如何判断自己是不是对事务隔离级别有了较为深入的理解...
第一步, 首先定义数组,将需要判断的权限添加进来 ,下面举例 添加读写权限。//要申请的权限private String[] mPermissions = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE};第二步,判断是否缺少权限/*** 判断是否缺少权限*/private...
subroutine &amp; action - varnish subroutine, code section, called in the flow, manipulate http header and other things,action, indicate the next step, used inside subroutine, in format "retu...
限流算法限流:通过对并发访问/请求进行限速,或者对一个时间窗口内的请求进行限速来保护系统,一旦达到限制速率则可以拒绝服务、排队或等待、降级等处理1.固定窗口算法(计数器算法)计数器算法使用计数器在一个周期内累计访问的次数,达到预定的值时,就触发限流策略。下一个周期计数清零,重新计数。这种算法比较简单,但是存在临界问题,即假设1min内限制访问量为1000,在第一个周期的最后五秒收到1000请求,在第二个周期的最开始五秒收到1000请求,实际上在十秒内已经收到2000请求,超过了限制的访问量。这种算法
这边博文的目的有以下几点:1、Win下安装cygwin2、在cygwin中安装php环境和php开发环境3、安装swoole扩展4、设置PHPStorm和cygwin完成PHPStrom的远程调试配置以下是正文部分:1、Win下安装Cygwin在Cygwin的官网下载Cygwin安装包,这儿提供64位安装包的下载地址:https://cygwin.com/setup-x86_64.exe ...
本文是回答一位知友的提问:单个 epoll + 线程池与每个线程一个 epoll 这两种架构哪个更适合大量短连接的场景?不少教程上都提到线程池适合大量的网络短连接的任务场景。但我总感觉这个优势有点站不住脚(单 epoll + 线程池模型),主要考虑到两点:1. 线程池的实现机制使得需要引入锁管理线程调度,这个开销在 per thread per epoll 模型中是不需要的。2. 大量的短连接导致需要经常对 epoll 进行添加和删除操作,线程池在进行这个任务是是需要对唯一的 epoll
unity5.6 导出gradle工程,Android Studio 导入问题以及解决
这两天一直在倒腾自己的网络课程设计,题目是本地以及远程主机端口开闭检测,很自然的想到了使用telnet,但在实际操作中发现win7下的telnet很是恶心,竟然无法使用。这里总结一下经验,给出win7下开启和使用telnet的方法,供大家参考。 首先,出于安全考虑,win7已经禁用了telnet这一功能,毕竟telnet是明文传输的,安全性很差。 知道了这一点就不奇怪为什么在win7下
转载自: 顾林海的博客http://blog.csdn.net/hai_qing_xu_kong/article/details/24265533 1.Android.permission.WRITE_USER_DICTIONARY允许应用程序向用户词典中写入新词2.android.permission.WRITE_SYNC_SETTINGS写入Google在线