例1:
'''
编写登录接口:
1.输入用户名和密码登录
2.输错三次锁定账户
3.下次登录还是上次的账户,提示锁定,直接退出(用到文件读写)
4.成功 后显示登录成功
'''
lock = "E:/Python_learn/day1/lock"
account = "E:/Python_learn/day1/account"
count = 0
flag = 1
lock_user = []
f1 = open(lock, 'r' )
lock_file = f1.readlines()
f1.close()
for i in lock_file:
i = i.strip( '\n' )
lock_user.append(i)
f2 = open(account, 'r' )
account_file = f2.readlines()
f2.close()
while True:
name = input( "input your name:" )
passwd = input( "input your password:" )
if name in lock_user:
print( "user is lock!" )
break
else :
count += 1
if count > 2:
print( "错误三次" )
with open(lock, 'a' ) as f:
f.write( "\n" + name)
break
else :
for i in account_file:
n1,p1 = i.strip().split()
if name == n1 and passwd == p1:
print( "welcome login!!" )
flag = True
else :
continue
if flag is True:
break
例2:
lock = "E:/Python_learn/day1/lock"
account = "E:/Python_learn/day1/account"
count = 0
flag = 1
lock_user = []
f1 = open(lock, 'r' )
lock_file = f1.readlines()
f1.close()
for i in lock_file:
i = i.strip( '\n' )
lock_user.append(i)
f2 = open(account, 'r' )
account_file = f2.readlines()
f2.close()
while True:
name = input( "input your name:" )
passwd = input( "input your password:" )
if name in lock_user:
print( "user is lock!" )
break
else :
count += 1
for i in account_file:
n1, p1 = i.strip().split()
if name == n1 and passwd == p1:
print( "welcome login!!" )
flag = True
else :
continue
if flag is True:
break
else :
if count > 2:
print( "错误三次" )
with open(lock, 'a' ) as f:
f.write( "\n" + name)
break
|