Search code examples
pythonif-statementauthenticationlogiclogical-operators

Why does my Or statement mess up my programming?


users = {} status = ""

def Menu(): global status status = input("Are you a registered user Y/N? Enter q to quit. \n")

if status == "Y" or "y":  #I wanted to make the option do capital and lowercase Y and N but when I
    OldUser()
elif status == "N" or "n":  #enter "n" it goes to OldUser() instead of Register()
    Register()

def Register(): name = input("Enter a username: ")

if name in users:
    print("The username is already used. Try again.")
else:
    pass_w = input("Enter a password: ")
    users[name] = pass_w
    print("\n Registration Complete! \n")

def OldUser(): login_n = input("Enter your username: ")

if login_n in users:
    login_p = input("Enter your password: ")

    if login_p == users[login_n]:
        print("\n Login Successful! \n")
    else:
        print("Password incorrect!")
else:
    print("\n Wrong user or user doesn't exist. \n")

while status != "q": Menu()


Solution

  • You need to do it like this:

    if status == "Y" or status == "y": 
        OldUser()
    elif status == "N" or status == "n":  
        Register()
    

    And their is another better solution to do it like this:

    if status.lower() == "y": 
        OldUser()
    elif status.lower() == "n":  
        Register()