#!/usr/bin/env python
Import Sys
Name =‘‘
pw=‘‘
Name_num =0
Pw_num =0
#black_list = []
WithOpen' A.txt ',' R ')As F:
For IIn F.xreadlines ():
Namelist.append (I.split () [0])
Pwlist.append (I.split () [1])
DefName_test (input_name, NameList):
If Input_nameIn NameList:
ReturnTrue
Else
ReturnFalse
Name =Raw_input (' Please input your name: ')
Name_num + =1
WhileTrue:
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
WhileTrue:
INDEX_PW = Pwlist[namelist.index (name)]
if pw = index_pw:
Print ' welcome '
break
else:
If Pw_num < PW = raw_input (" PASSWD is Error,please input your passwd again: ')
Pw_num +=1
else:
print Sorry,today you had to lose the wrong password three times '
Bao 123
Zhang 456
Some small programs that will be blacklisted later < Span style= "color: #cc7832; Font-weight:bold; " >
There is a program that my friend gave me, feel his more concise, look comfortable:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
# @Time: 2016/7/29 11:46
# @Author: Big_bao
Import Sys
DefName_test (input_name, NameList):
If Input_nameIn NameList:
ReturnTrue
Else
Print' Name is None. '
ReturnFalse
DefPw_test (PW, INDEX_PW, innerloopnumber=0):
If pw = = INDEX_PW:
Print' Welcome. '
inn = innerloopnumber+1
Return Inn
Else
Print' Password is None. '
NameList = []
Pwlist = []
WithOpen' A.txt ',' R ')As F:
For IIn 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
WhileTrue:
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 sys.exit ()
if Pw_num== print ' You have no chance '
sys.exit (
if Inloopnum_== 1:
sys.exit ()
< Span style= "color: #cc7832; Font-weight:bold; " > Thank the friend who is far away in Chengdu Usual pointers
Python Login Interface