为什么我输入正确的用户名时提示访问被拒绝?

Why is it saying access denied when I input the username correctly?

嘿,我已经写了这段代码,但是我看不出它有什么问题,它说用户名是错误的,但是如果我打印它,它 returns 正是我输入的内容。

ea = input("Do you already have an account")
if ea == "Yes" or ea == "yes":
    Ausername = input("Input your username")
    Apassword = input("Input your password")

    f=open("login.txt","r")
    lines=f.readlines()
    username=lines[0]

    if (Ausername) == (username):
        print("Welcome to the quiz")
    else:
        print("Access denied")

    f.close()

else:
    name = input("Input your name")

    yeargroup = input("Input your year group")

    age = str(input("Input your age"))

    firstusername = ((name[0]+name[1]+name[2])+(age))
    print((firstusername)+(" is your username"))
    firstpassword = input("Enter what you want your password to be")
    print(firstusername)
    print(firstpassword)


    login = open("login.txt","a")
    login.write(firstusername + "\n" + name + "\n" + yeargroup + "\n" + age + "\n" + firstpassword + "\n")
    login.close()

print("---------------------------------------------------")

文件数据默认以尾随换行符读入。在比较字符串之前,您是否尝试调用 str.strip

if Ausername == username.strip():
    ...

此外,如果您想进行不区分大小写的比较,您应该使用 str.lower 将您的字符串转换为小写以减少搜索的大小 space:

if ea.lower() == "yes":
    ...