代码如下:
dic={
'user1':{'password':'123','count':0},
'user2':{'password':'123','count':0},
'user3':{'password':'123','count':0},
}
while True:
name=input('username>>:')
if not name in dic:
print('用户不存在')
continue
if dic[name]['count']>2:
print('尝试次数过多,锁定')
continue
password=input('password>>:')
if password == dic[name]['password']:
print('登录成功')
break
else:
print('用户或密码错误')
dic[name]['count']+=1
解析如下:
dic={
'user1':{'password':'123','count':0},
'user2':{'password':'123','count':0},
'u
本文介绍如何使用Python编写一个简单的登录程序,如果连续尝试登录三次失败,账户将被锁定。通过这段代码,读者可以了解基本的输入验证和错误处理机制。
最低0.47元/天 解锁文章
2422

被折叠的 条评论
为什么被折叠?



