要求:用python模拟用户登录操作,当用户登录失败时,提示用户剩余登录次数和重新输入登录,当用户登录三次失败时,提示用户"你的登录次数超过三次,你的账号已经被锁定,拒绝登录!",如果用户登录成功,则提示用户登录成功!
完整代码:(while循环)
import random
users = {'zhang': 'abc', 'li': '123456', 'wan': 'abc123'}
u_id = input("请输入账号:")
pw = input("请输入密码:")
verification_code = random.randint(1001, 9999)
print('验证码:', verification_code)
count = 1
while True:
if count > 3:
print("你的登录次数超过三次,你的账号已经被锁定,拒绝登录!")
break
else:
ver_code = int(input("请输入验证码:"))
count += 1
if u_id in users.keys() and pw == users.get(u_id):
if ver_code == verification_code:
print("你已经成功登录!")
break
else: