我得到了这个程序,它是有效的。在
#######################################################################
## This program simulates a login screen.
## The username and passwords are stored in an input file.
#######################################################################
f=open('usernames.txt')
usernames=[]
passwords=[]
for index in range(10):
line = f.readline().strip()
usernames.append(line)
line = f.readline().strip()
passwords.append(line)
user = input("Username: ")
found = False
for index in range(10):
if user == usernames[index]:
found = True
passwrd = input("Password: ")
if passwrd == passwords[index]:
print("Access Granted")
else :
print("Username and password do not match")
break
if (not found):
print("Username not found")
我需要修改这个程序,使它反复要求一个有效的用户名和密码,直到访问被授予。我认为这应该很简单,我之所以有这么多麻烦是因为我不明白为什么strip()
的调用需要在那里。我不明白程序如何将文本文件的索引与它后面的索引相匹配。在
相关问题 更多 >
编程相关推荐