首页 > 代码库 > Python学习之路3?简单的用户三次输入三次错误锁定

Python学习之路3?简单的用户三次输入三次错误锁定

#_*_coding:utf-8_*_
#!/usr/bin/env python

# dic={‘tom‘:‘123‘,‘egon‘:‘456‘,‘lxh‘:‘111‘}
#
# count=0
# while count < 3:
# name=input(‘请输入用户名: ‘).strip()
# passwd=input(‘请输入密码:‘).strip()
# print(type(name),type(passwd))
# if name in dic and passwd == dic[name]:
# print(‘登录成功‘)
# break
# else:
# print(‘用户名或者密码错误‘)
# count+=1

# if name in dic:
# user_pass=dic[name]
# if user_pass == passwd:
# print(‘登录成功‘)
# break
# else:
# print(‘密码错误,重新输入‘)
# count+=1
# else:
# print(‘用户不存‘)
# count+=1

 


# dic={‘tom‘:‘123‘,‘egon‘:‘456‘,‘lxh‘:‘111‘}
dic={
‘tom‘:{‘passwd‘:‘123‘,‘count‘:0},
‘egon‘:{‘passwd‘:‘456‘,‘count‘:0},
‘lxh‘:{‘passwd‘:‘111‘,‘count‘:0}
}
while True:
name=input(‘请输入用户名: ‘).strip()
if name in dic and dic[name][‘count‘]==3:
print(‘你的用户被锁定了‘)
continue
passwd=input(‘请输入密码:‘).strip()
if name in dic:
if passwd == dic[name][‘passwd‘]:
print(‘登录成功‘)
break
else:
dic[name][‘count‘] += 1
print(‘用户登录失败的次数‘,name,dic[name][‘count‘])
else:
print(‘用户不存在‘)

Python学习之路3?简单的用户三次输入三次错误锁定