我正在尝试创建一个在单独的文本文件中检查用户名的系统,如果它不存在,请告诉他们并提示他们重新输入密码。这在他们第一次获得用户名不正确时起作用,但是随后它会多次重复该消息。 这是我到目前为止的代码:
private static final String DATABASE_NAME = "BookDB";
public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
答案 0 :(得分:0)
我甚至不知道如何编译,只要你在不同的标签栏中有一个“其他”而不是“if”。也许这可能是你的问题,因为你正在以你不想要的方式测试事物。此外,现有用户名只读一次,不会更改。所以“if”将是真实的一百倍!
答案 1 :(得分:0)
我认为你不必使用所有循环的东西。由于每个用户名都是一行..我们可以使用下面的文件可能不会很大..比如100mb ..
def existingUser():
existingUsername = input("What is your user name?")
if existingUsername in open('logins.txt').read():
correctPassword()
else:
print("That doesn't seem to match. Please try again")
答案 2 :(得分:0)
如果我理解正确,你想检查给定的用户名是否有效,如果错误,你想要给用户99个机会
<强> input.txt中
sandeep
lade
venkat
代码(此处最大机会为3)
def existingUser():
annoyingProblem = 0
print("Welcome back")
while True:
existingUsername = str(raw_input("What is your user name?"))
with open("infile.txt", "r") as logins2:
for num, line in enumerate(logins2, 1):
if existingUsername in line:
correctPassword()
print("That doesn't seem to match. Please try again")
annoyingProblem = annoyingProblem + 1
if annoyingProblem == 3:
print("exceeded number of attempts")
break
输出
>>> existingUser()
Welcome back
What is your user name?nope
That doesn't seem to match. Please try again
What is your user name?nope
That doesn't seem to match. Please try again
What is your user name?nope
That doesn't seem to match. Please try again
exceeded number of attempts