编写登陆接口
要求:
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
user = [['yefei','123'],['yf','123'],['mm','123']]
count = 0
error_count = 0
while count < 3:
user_name = input("请输入用户名:").strip()
user_password = input("请输入密码:").strip()
f = open(file= 'error.txt',mode='r',encoding='utf-8')
data = f.read()
if user_name in data:
print("对不起!用户%s被锁定!请使用其它用户名登录!" % user_name)
else:
for i,v in enumerate(user):
if user_name == v[0] and user_password == v[1]:
print("欢迎,登陆成功!")
exit()
else:
f = open(file='error.txt',mode='a+',encoding='utf-8')
error_count += 1
if error_count == 9:
f.write('%s状态:锁定' % user_name)
print('您的用户密码输入有误!')
count += 1
f.close()
测试结果如下:

浙公网安备 33010602011771号