+ 1
for and while looping with list problem
I have tried to make simple for and while looping with list element, but there's still something IndexError Here is the code: list_registered_username = ['max', 'paul'] #to login reload = 1 while reload == 1: username = input("username: ") for i in range(len(list_username)+1): if username != list_username[i]: reload = 1 elif username == list_username[i]: reload = 0 #next step func... And the IndexError is located at line: if username != list_username[i]: IndexError: list index out of range Process finished with exit code 1 I'll thank to someone who can fix it
3 Antworten
+ 3
This line:
for i in range(len(list_username)+1):
shouldn't have the "+ 1" because your list doesn't have an index that big,
+ 1
Use for i in range(len(list_registered_username)
I suggest you change the username to lowercase incase the user enters the first alphabet in uppercase
username=input("username: ").lower()
+ 1
@slick oh thank you for answering
@Roy thanks for your responding