Python 输错4次用户名密码需要输入验证码

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/hi_job/article/details/100562108
time = 0
login_success = False
USER_NAME = "alex"
PWD = "alex123"
CHECK_CODE = "123"

while time < 4:
    user_name = input("请输入您的用户名: ")
    pwd = input("请输入您的密码: ")

    if user_name == USER_NAME:
        if pwd == PWD:
            print("恭喜您登录成功")
            login_success = True
            break
        else:
            print('您的用户名或密码错误,请重新输入')
            time = time + 1
    else:
        print("您的用户名或密码错误,请重新输入")
        time = time + 1
if not login_success:
    while True:
        check_code = input('请输入验证码: ')
        user_name = input("请输入您的用户名: ")
        pwd = input("请输入您的密码: ")
        if check_code == CHECK_CODE:
            if user_name == USER_NAME:
                if pwd == PWD:
                    print("恭喜您登录成功")
                    break
                else:
                    print("您的用户名或密码错误,请重新输入")
            else:
                print("您的用户名或密码错误,请重新输入")
        else:
            print("验证码错误,重新输入")

猜你喜欢

转载自blog.csdn.net/hi_job/article/details/100562108