mercredi 3 mars 2021

Why does my if statement activate even though the conditions aren't met?

Simple question here, made a little program asks the user to create a username and password. Every thing worked until I added this "if user" statement. It should restart the loop if I enter 'x' or 'X' but it restarts it regardless of what I enter. What's happening here?

db = {}
num_of_entries = 0


def addToDict(a, b):
    db[a] = b
    print(f"User created: '{a}'")


def removeFromDict(key):
    del db[key]
    print()
    print(f"User '{key}' has been removed.")


while True:
    clear = "\n" * 100
    print()
    print("""
Hi there!     
Would you like to create a new account or delete an existing one?
          ('Create' to create, 'Delete' to delete)
""")

    choice = input("> ").upper()

    if choice == 'CREATE':
        print(f'{choice} mode selected.')
        print()
        user = input("Please enter a username: ")
        if user == 'X' or 'x':
            continue
        else:
            if user not in db:
                passW = input("Please enter a password: ")
                print(clear)
                print()
                addToDict(user, passW)

Aucun commentaire:

Enregistrer un commentaire