jeudi 17 septembre 2020

My ussername checker keeps saying all names are available, despite if/else test

I'm attempting to make a simple, small, practice program for checking usernames using if-elif-else statements.

current_users = ['Enrique', 'Jose', 'Pablo', 'John', 'Jake']
new_users = ['Mike', 'Tom', 'Bowser', 'John', 'Howard', 'Ben']

'''for user in current_users:
        user = user.lower()
        print(user)

   for user in new_users:
        user = user.lower()
        print(user)
'''


for user in new_users:
    if user.lower() == current_users:
        print(f"{user}: That username is taken.")
    else:
        print(f"{user}: That username is available.")

I expect for it to print the message "That username is taken" for a username that's on both the new_user list and the current_user list, but instead, they all evaluate the True when I run them in the Sublime text editor.

I know it's a logic error because no actual error message is given, but I can't quite see it yet.

I've tried inverting the loop by starting with checking if a username from the new_users list is NOT from the current_users list.

As you can see, I've tried changing all of the usernames to lowercase to see if it would help, but it doesn't.

Aucun commentaire:

Enregistrer un commentaire