I am writing a Python script that takes a username and determines if it is a valid username. If it is different from any other username and is greater than 6 characters, it is added to a list of usernames. If the username is shorter than 6 characters, or is the same as an existing username, the program ends and informs the user of the invalid name. My issue is if I put in a new username which gets added to the list, and then put in that same username again, it does not inform me that it is already taken.
name_list = []
username = input("input your new username: ")
if len(username) < 6:
print('username is too short')
elif len(username) >6:
if username in name_list :
print('username taken')
elif username not in name_list:
name_list.append(username)
Say I input JonnyBoy as the username; it gets added to the name_list. If I then run the program again using the same username, it does not recognize it is the same as an existing username.