首页 技术 正文
技术 2022年11月9日
0 收藏 984 点赞 2,761 浏览 1763 个字
#!/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 Falsename = 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 Falsedef 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 = 0name = 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()感谢这位远在成都的朋友平时的指点
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902