我目前正在尝试制作一个程序,要求用户输入用户名和密码。如果他们注销,他们必须能够重新输入密码和用户名。无论我怎么看,我都会收到“用户名和密码不正确”。
#Ask user for username and password
def main():
username = input("Please enter a username: ")
password = input("Please enter a desired password: ")
save(username, password)
#trys to log user on
def save(username, password):
if username == "username" and password == "password":
login(username)
else:
print("Username and/or password is incorrect. Please try again!")
main()
#Welcomes
def login(username):
print("You have successfully logged in!")
print()
print("Welcome user!")
print()
commands()
#run a simple output
def commands():
command = input("What would you like me to do for you today?: ")
if command == "log off" or command =="quit":
print("You have logged off")
main()
else:
print("Unknown command")
commands()
main()
答案 0 :(得分:0)
老兄,你正在检查静态值的用户名和密码。
if username == "username" and password == "password":
因此,任何其他用户名或密码都会给您错误:
用户名和/或密码不正确。请再试一次!
再次使用“username”作为用户名,使用“password”作为密码,你肯定不会得到错误。