python 登陆接口

#!/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()

感谢这位远在成都的朋友平时的指点


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值