【发布时间】:2016-12-22 02:22:07
【问题描述】:
我在一个名为“SortedUniqueMasterList.txt”的文本文件中有一个密码列表。我正在编写一个程序,它接受用户输入并检查输入的密码是否在列表中。
这是我的代码:
Passwords = []
with open("SortedUniqueMasterList.txt", "r", encoding = "latin-1") as infile:
print("File opened.")
for line in infile:
Passwords.append(line)
print("Lines loaded.")
while True:
InputPassword = input("Enter a password.")
print("Searching for password.")
if InputPassword in Passwords:
print("Found")
else:
print("Not found.")
但是,我输入的每个密码都返回“未找到。”,即使是我确定的密码也在列表中。
我哪里出错了?
【问题讨论】:
-
你能否提供一条线的样子?用户输入会是什么?
-
Passwords.append(line.strip()) 对我有用
-
@downshift:您应该将其发布为答案。
-
@BrenBarn,好吧,虽然我看到用户因为单线修复而受到抨击,所以我只是犹豫不决
-
现在正在处理这个问题,但是请在您的 while 语句之前打印行列表的样子
标签: python python-3.x search text