# 编写登录接口
# 基础需求:
# 1. 让用户输入用户名密码
# 2. 认证成功后显示欢迎信息
# 3. 输错三次后退出程序
# 升级需求:
# 1. 可以支持多个用户登录(提示, 通过列表存多个账户信息)
# 2. 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)
try_times = 0
list_username = [‘linda‘,‘emily‘,‘yu‘]
t_password = {‘linda‘: 123, ‘emily‘: 123, ‘yu‘: 123}
f = open(‘try.txt‘,‘r‘)
lock_file = f.read()
print("read file %s" % lock_file)
f.close()
username = input("could you enter your name?: ")
#
for i in range(1):
if lock_file == username:
print("your account is locked, could not login right now. ")
exit()
else:
pass
while try_times < 3:
password = int(input("please enter your password:"))
if username in list_username[:] and password in t_password.values() :
print("welcome %s to login!" % username)
break
elif username in list_username[:] and password not in t_password.values() :
print("password is not correct")
try_times += 1
while try_times == 3 :
print("sorry, try 3 times, locked your account.")
f = open("try.txt",‘w‘)
f.write(‘\n%s ‘ % username)
break
原文:https://www.cnblogs.com/demilyc/p/9985228.html