在列表/文件中编写比较密码和用户名以查看它们是否匹配(无法使用字典或其他导入的内容)

时间:2018-11-14 17:29:50

标签: python

我必须编写一个代码来打开一个包含用户名的文件夹和另一个包含密码的文件夹。然后,我必须将它们放在列表中并进行比较。然后,用户输入用户名或密码。如果用户名不存在或密码错误,则拒绝用户。如果信息正确,用户将收到一条消息,表明他们已经登录。然后,包含分数的文件必须能够打开,放入列表并进行编辑。这是我到目前为止所拥有的。我可以打印所有文件/列表,但是我需要弄清楚如何比较内容。请帮我提供此代码!

#Part 1: Opening the files and grabbing data
filename1 = "c:\\Users\\Anna Hamelin\\Documents\\Python 
Scripts\\SourceCode\\Project2\\usernames.txt"
file = open(filename1, "r")

#Usernames
users = file.read()
usernameslist = [line.strip() for line in open("c:\\Users\\Anna 
Hamelin\\Documents\\Python Scripts\\SourceCode\\Project2\\usernames.txt")]
print(users)                #Check file
print(usernameslist)       #Check usernames list

filename2 = "c:\\Users\\Anna Hamelin\\Documents\\Python 
Scripts\\SourceCode\\Project2\\passwords.txt"
file = open(filename2, "r")

#Passwords
passwords = file.read()
passwordslist = [line.strip() for line in open("c:\\Users\\Anna 
Hamelin\\Documents\\Python Scripts\\SourceCode\\Project2\\passwords.txt")]
print(passwords)            #Check file
print(passwordslist)       #Check passwords list

#Scores
filename3 = "c:\\Users\\Anna Hamelin\\Documents\\Python 
Scripts\\SourceCode\\Project2\\scores.txt"
file = open(filename3, "r")

scores = file.read()
scoreslist = [line.strip() for line in open("c:\\Users\\Anna 
Hamelin\\Documents\\Python Scripts\\SourceCode\\Project2\\scores.txt")]
print(scores)           #Check file
print(scoreslist)       #Check scores

0 个答案:

没有答案