Python的两个变量是相同的,但是Python并不认为它们

2024-05-07 23:43:32 发布

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

我正在做一个程序,有一个登录;它根据用户的输入检查输入。但是,即使输入了正确的密码,它也不会接受:

for i in range(5):
    existingUsername = input("What is your user name?")
    if existingUsername in open('logins.txt').read():
        with open("logins.txt", "r") as myFile:
            for num, line in enumerate(myFile, 1):
                if existingUsername in line:
                    passwordLine = num + 1
                    passwordAttempt = input(str("What is your password?"))
                    passwordText = linecache.getline("logins.txt", passwordLine)
                    if passwordAttempt == passwordText:
                        print("That is correct")
                        quizSelection()
                        break
                    else:
                        print("That doesn't seem to match. Please try again")

它引用的文本文件中只有Har16和Google,在不同的行中,Har16在顶部


Tags: intxtforinputyourifisline