入门级练习题(16-)

Q16:1.系统随机生成4位数,作为登录验证,2.用户输入用户名和密码还有验证码,3.共3次登录机会,但如果是验证码错误,不扣次数

重点:理解验证码的循环

from random import randint
num=0
verify_code = ''
while num < 4:
verify_code += chr(randint(65,90))
num += 1
print(verify_code)

username='zong'
password='123'

num=1
while 1:
uname = input("请输入账号:")
upwd = input("请输入密码:")
vi_code = input(f"请输入验证码{verify_code}:")
if vi_code.upper() == verify_code:
print("验证码正确")
if num == 3:
print("次数已经用完,账号被冻结")
break
elif uname == username and upwd == password:
print("登陆成功")
break
else:
print(f"用户名或密码错误,你还有{3-num}次机会")
num += 1
continue
else:
print("验证码错误,请重新输入")
continue

猜你喜欢

转载自www.cnblogs.com/jiangzongyou/p/11517295.html
今日推荐