Python学习周末练习1-用户登录

用户登录验证

:
1.用户登录输入账号、密码、4位随机大写字母验证码
2.验证码错误重新输入
3.有三次机会输入账号密码
count = 1
while count <= 3 :
    from random import randint
    num = 0
    verify_code = "" # 创建一个空字符串放验证码
    while num < 4:
        verify_code += chr(randint(65, 90))
        num += 1

    usernum = input("请输入账号")
    code = input("请输入密码")
    verify_code_1 = input("请输入验证码(%s)" %verify_code)

    if usernum == "左志博" and code == "123" :
        if verify_code_1 == verify_code:
            print("输入正确")
            break
        else :
            print("验证码错误,请重新输入")
            continue
    else :
        print("输入错误,你还有%s次机会" % (3-count))
    count += 1

猜你喜欢

转载自www.cnblogs.com/Dani/p/9973984.html