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

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("验证码错误,重新输入")

  

posted @ 2019-09-05 17:22  CharmingLiu  阅读(628)  评论(0编辑  收藏  举报
ヾ(≧O≦)〃嗷~