'''
1.输入用户名和密码
2.认证成功后显示欢迎信息
3.输错三次后锁定
'''
"""
1.对于用户输入密码的时候,输入错误的异常buhuo
2.如果用户在输入的时候,输入的账号不存在已经锁的列表中,则需要再次进行新的注册
"""
right_item = dict() # 用来存储第一次用户输入的正确的user和pwd
err_list = list() # 用来存储用户输入超过三次的user
print('<<<<<<<欢迎您注册本系统>>>>>>>')
user = input('请输入您账号:')
pwd = int(input('请输入您的密码:'))
print('您的账号已生效,下次请用该账号:{}登陆本系统'.format(user))
right_item['user'] = user
right_item['pwd'] = pwd
print('')
print('<<<<<<<欢迎您登陆本系统>>>>>>>')
i = 0
a = 3
while i < 3:
try:
user = input('请输入您的账号:')
pwd = int(input('请输入您的密码:'))
if user == right_item['user'] and pwd == right_item['pwd']:
print('欢迎您:{}再次登陆本系统'.format(user))
break
elif user != right_item['user'] or pwd != right_item['pwd']:
print('你的登陆账号或密码有误,请检查后重新登陆,本系统只有3次试登陆')
err_list.append(user)
a = a - 1
print('您还有{}次机会'.format(a))
if a == 0:
print('对不起,您今天的试登陆次数已用完,请您明天再来登陆')
break
else:
break
i += 1
except Exception as result:
print(result)
print('')
print('<<<<<<<欢迎您登陆本系统>>>>>>>')
i = 0
while i < 4:
try:
user = input('请输入您的账号:')
pwd = int(input('请输入您的密码:'))
if user == right_item['user'] and pwd == right_item['pwd']:
print('欢迎您:{}再次登陆本系统'.format(user))
break
else:
for li in err_list:
if user == li and user != right_item['user']:
print('对不起,该用户{}已被锁定,暂时无法登陆'.format(user))
except Exception as result:
print(result)
i += 1
转载于:https://www.cnblogs.com/victorstudy/p/11058585.html