对于我的类,我应该编写一个代码,询问用户需要输入多少对用户名和密码。之后,应该有那么多的用户名和密码,每行一个。我想我们也应该把它们存到字典里。然后,您要求用户输入用户名和密码,然后与字典中的内容相比,检查组合是否正确。这是我的东西
num_passwords_user = int(input("How many pairs of usernames/passwords? "))
username_input = ''
password_input = ''
counter = 0
while counter < num_passwords_user:
username_input = str(input("Enter username for the database: "))
password_input = str(input("Please enter your password for the database: "))
database = {username_input: password_input}
counter += 1
print(database)
ask1 = input("Enter username to login: ")
ask2 = input("Enter password to login: ")
while (ask1 and ask2) not in database:
if (ask1 and ask2) not in database:
print("Incorrect, try again.")
username_input = (input("Enter username: "))
ask = input("Enter password: ")
print("Access Granted")
问题在于第二个while循环。当我输入一个值时,它总是打印“不正确,再试一次”。我不知道如何解决这个问题
这就是你需要的
第二个循环也没有正确地纠正
ask1
和ask2
数据库只是不匹配,所以请尝试以另一种方式保存数据
相关问题 更多 >
编程相关推荐