Jan-05-2017, 07:09 AM

Now for the purpose of knowledge and learning could you iterate on simple loop / list basics. I'm using PyCharm IDE, python v 3.5 if that makes any difference.
I would like to understand how to get a simple loop that checks the usernames and continues to check them until a username thats different from one written in the list is entered. I need to understand what is happening and why I'm having such different results with the variations I've tried. I have tried several different loops and when testing some work to stop a repeated username for the first iteration but lets it slide in the next iteration or there is a matter where it will stop a repeat of the same username being entered in several times but when a different username thats still in the list is use it will let it pass. Almost like whats being entered into username input is giving n[0] the value of username and at the same time checking the other parts of n[0]. I don't really know how to eplain it so I'll jot down the loop / list that I need to understand. If anyone could help me understand what's happening and on a basic level consisting of loop / lists basics how do I fix the issue and why that solution would work.
username = input("Enter a username: ") usrdatalist = [['josh' , 'mi'], ['ryan' , 'th'], ['loki' , 'ch']] # Create loop to check username for n in usrdatalist: while (n[0] == username): username = input("Name taken, enter new name: ") if (n[0] != username): print("Account created!")
Output:/usr/bin/python3.5 /root/PythonProjects/video_game/looplistcheck.py
Enter a username: josh
Name taken, enter new name: ryan
Account created!
Name taken, enter new name: loki
Account created!
Name taken, enter new name: josh
Account created!
Process finished with exit code 0