for and while looping with list problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

15th Nov 2020, 9:39 AM
Hafizhul Qisthi M
Hafizhul Qisthi M - avatar
3 Answers
+ 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,
15th Nov 2020, 10:00 AM
Slick
Slick - avatar
+ 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()
15th Nov 2020, 10:00 AM
Roy
Roy - avatar
+ 1
@slick oh thank you for answering @Roy thanks for your responding
15th Nov 2020, 10:40 AM
Hafizhul Qisthi M
Hafizhul Qisthi M - avatar