函数不可调用?

2024-06-01 03:58:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图学习python,但在编写一个简单的登录页面时遇到了一个问题

def Login():
    
    print("Login System")
    print("\n")
    print("1 - Login")
    print("2 - Create an Account")
    PassCheck = False
    UserCheck = False
    Login = False
    selec = input("What do you want to do?: ")

    if selec == '1':
        print("Input your credentials")
        usernameLog = input("Input you username: ")
        usertxt = open("user.txt", "r")
        if usernameLog == usertxt.read():
            UserCheck = True
        else:
            UserCheck = False
            usertxt.close()

        passwordLog = input("Input you password: ")
        passwordtxt = open("pass.txt", "r")
        if passwordLog == passwordtxt.read():
            PassCheck = True
        else:
            PassCheck = False
            passwordtxt.close()
        
        if UserCheck and PassCheck == True:
            print('\n')
            print('\n')
            print('You Logged In')
        else:
            print('\n')
            print('\n')
            print('Username or password incorrect')
            Login()
Login()

它以前是工作的,只是停止了工作。它表示Login()函数不可调用


Tags: youfalsetrueinputiflogindoelse
1条回答
网友
1楼 · 发布于 2024-06-01 03:58:17

尝试更改Login变量的名称。最好将函数名改为小写。 也可以尝试下面的代码。我只是将(如果selec==“1”)更改为(如果selec==1)

def Login(): 

    print("Login System")
    print("\n")
    print("1 - Login")
    print("2 - Create an Account")
    PassCheck = False
    UserCheck = False

    selec = input("What do you want to do?: ")

    if selec == 1:
        print("Input your credentials")
        usernameLog = input("Input you username: ")
        usertxt = open("user.txt", "r")
        if usernameLog == usertxt.read():
            UserCheck = True
        else:
        UserCheck = False
        usertxt.close()

        passwordLog = input("Input you password: ")
        passwordtxt = open("pass.txt", "r")
        if passwordLog == passwordtxt.read():
            PassCheck = True
        else:
            PassCheck = False
            passwordtxt.close()
    
        if UserCheck and PassCheck == True:
            print('\n')
            print('\n')
            print('You Logged In')
        else:
            print('\n')
            print('\n')
            print('Username or password incorrect')
            Login()

Login()

相关问题 更多 >