博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 登陆接口
阅读量:7104 次
发布时间:2019-06-28

本文共 2048 字,大约阅读时间需要 6 分钟。

#!/usr/bin/env python import sys name = '' pw='' name_num = 0 pw_num = 0 #black_list = [] with open('a.txt','r') as f: for i in f.xreadlines(): namelist.append(i.split()[0]) pwlist.append(i.split()[1]) def name_test(input_name, namelist): if input_name in namelist: return True else: return False name = raw_input('Please input your name:') name_num +=1 while True: if name_test(name, namelist): break else: if name_num < 3: name = raw_input('Name is error,Please input your name again:') name_num += 1 else: print 'Sorry,Today you have mistyped user name three times' sys.exit() pw = raw_input('Please input your password:') pw_num +=1 while True: index_pw = pwlist[namelist.index(name)] if pw == index_pw: print 'welcome' break else: if pw_num < 3: pw = raw_input('Passwd is error,Please input your passwd again:') pw_num +=1 else: print 'Sorry,Today you have to lose the wrong password three times' sys.exit() 这里的a.txt的格式是
bao 123 zhang 456 后面还要加入黑名单的一些小程序 这里还有一个朋友给我的程序,感觉他的更加的简练,看着舒服:
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time    : 2016/7/29 11:46 # @Author  : Big_Bao import sys def name_test(input_name, namelist): if input_name in namelist: return True else: print 'Name is None.' return False def pw_test(pw ,index_pw, innerloopnumber=0): if pw == index_pw: print 'Welcome.' inn = innerloopnumber+1 return inn else: print 'Password is None.' namelist = [] pwlist = [] with open('a.txt','r') as f: for i in f.xreadlines(): namelist.append(i.split()[0]) pwlist.append(i.split()[1]) index_pw = [] name = '' pw='' name_num = 0 pw_num = 0 inloopnum = 0 name = raw_input('Please input your name:') name_num +=1 while True: if name_test(name, namelist): index_pw = pwlist[namelist.index(name)] pw = raw_input('Please input your password:') pw_num +=1 inloopnum_ = pw_test(pw, index_pw,innerloopnumber=inloopnum) else: name = raw_input('Please input your name again:') name_num +=1 if name_num ==3: print 'You have no chance.' sys.exit() if pw_num==3: print 'You have no chance' sys.exit() if inloopnum_==1: sys.exit() 感谢这位远在成都的朋友平时的指点

转载地址:http://cokhl.baihongyu.com/

你可能感兴趣的文章
lodash(二)对象+循环遍历+排序
查看>>
Eclipse快捷键大全
查看>>
Java -- 获取MAC地址
查看>>
Visual Prolog 的 Web 专家系统 (1)
查看>>
void 指针的转换
查看>>
再议Unity优化
查看>>
localhost兼容js不能用
查看>>
Makefile 10——打造更专业的编译环境-huge项目
查看>>
Create and Call HttpHandler in SharePoint
查看>>
pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")
查看>>
树莓派与window 10组成的物联网核心:让人失望
查看>>
Servlet的异常处理
查看>>
支付宝 app支付 沙盘使用
查看>>
Redis持久化配置-AOF
查看>>
计算机网络的应用层简单介绍:
查看>>
需求管理之客户需求何时休?
查看>>
Java进化? Kotlin初探与集成Android项目
查看>>
URL中的#
查看>>
CentOS自带mysql配置(密码更改、端口开放访问、添加进系统启动项)
查看>>
MYSQL中动态行数据转列数据
查看>>