I'm working trough the Python Crash Course book and I am doing this assignment.
Do the following to create a program that simulates how websites ensure that everyone has a unique username.
- Make a list of five or more usernames called
current_users
.- Make another list of five usernames called
new_users
. Make sure one or two of the new usernames are also in thecurrent_users
list.- Loop through the
new_users
list to see if each new username has already been used. If it has, print a message that the person will need to enter a new username. If a username has not been used, print a message saying that the username is available.- Make sure your comparison is case insensitive. If
'John'
has been used,'JOHN'
should not be accepted.
I can see if a username in one list is in another with.
current_users = ["John", "Admin", "Jack", "Ana", "Natalie"]
new_users = ["Pablo", "Donald", "Calvin", "Natalie", "Emma"]
for username in new_users:
if username in current_users:
print("Username unavailable.")
else:
print("Username available.")
Now for the case insensitive part I know about the .lower() method, but not sure how to convert a list item to lowercase in the loop. I could do if username.lower() in current_users
, which wouldn't work because I need to covert current_users somehow. Is there a better way then just doing .lower()
for both lists before the loop.