使用python写一个登录小程序,登录三次锁定

本文介绍如何使用Python编写一个简单的登录程序,如果连续尝试登录三次失败,账户将被锁定。通过这段代码,读者可以了解基本的输入验证和错误处理机制。
摘要由CSDN通过智能技术生成

代码如下:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值