我正在做一个程序,有一个登录;它根据用户的输入检查输入。但是,即使输入了正确的密码,它也不会接受:
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在顶部
当您运行
passwordText = linecache.getline("logins.txt", passwordLine)
时,如果您的文件有多行,它可能会返回结尾带有\n
的字符串相关问题 更多 >
编程相关推荐