0

So i am trying to make this program where it asks for a username and password then it saves it, then you can log in with it and when you do lock in, it'll give you two options, you can type HELP or you can type COMMAND and if you type something else it will respond with "That is not a valid command" but when i do the while input3 != "HELP" or "LOCK" statement, it will just say that is not a valid command, even if i do type HELP or LOCK so what am I doing wrong and how can I use the or command

print("Hello, please register below")
user = input("Username: ")
password = input("Password: ")
print("Thank you for registering, please log in below")
print()
print("Hello, please log in below")
while 1 == 1:
    def menu():
        print("HELP for more options")
        print("LOCK to exit and secure system")

    input1 = None
    input2 = None
    input3 = None


    while input1 != user:
        input1 = input("Username: ")
    while input2 != password:
        input2 = input("Password ")
    menu()
    input3 = input("Command: ")
    while input3 != "HELP" or "LOCK":
        print("Please input a valid command")
        input3 = input("Command: ")
    if input3 == "HELP":
        print("Type LOCK to secure system and exit program, or tpye HELP to display this message again")
    input3 = input("Command: ")
    if input3 == "LOCK":
        print("System is now locked, exiting program")
  • Additional comment: I would suggest writing just `while True` in your first while statement. – OBu Jun 28 '14 at 05:13

1 Answers1

3

Your while loop condition logic is flawed. The or statement doesn't work the way you think it does. Do this instead:

while input3 not in ("HELP", "LOCK"):

Read this famous stackoverflow question that explains the logic flaw in detail

Community
  • 1
  • 1
sshashank124
  • 31,495
  • 9
  • 67
  • 76