基本上,我制作了一个接受用户输入的基本登录程序。但是,它目前只允许一个用户名和密码组合。我试图让它接受多个用户名和密码,但不知道如何。我是 python 新手,我知道我的代码很糟糕/混乱。这就是我一直试图让它接受多个登录组合:
output = open("logfile.txt", 'a')
login = input("please enter the correct username and password\n")
a = ("username password")("username1 password1")
if a in login:
print("successfully logged in")
import time
localtime = time.asctime(time.localtime(time.time()))
output.write("Somebody successfully logged in at ")
output.write(localtime)
output.write("\n")
output.close()
else:
print("access denied.")
import time
output = open("logfile.txt", "a")
localtime = time.asctime(time.localtime(time.time()))
output.write("Somebody unsuccessfully logged at ")
output.write(localtime)
output.write("\n")
output.close()
` 当我只添加另一个“if”块时,它也会运行 else 块。此外,当我只有“a”值“用户名密码”时,它可以工作。问题是当我尝试拥有多个我相信的价值观时。