I am a beginner of python, I tried to test the while loop. For below code, I can get the answer, but still get the out of range error. I know the available seat is much larger than the name list, and all people can get a seat. The result showed the answer that I want. But it shows out of range. How can fix the out of range problem? Thanks
name_list=["Peter", "John", "Gary", "Amy"]
available_seat=10
entered_people=0
while available_seat > entered_people:
element=name_list[entered_people]
print(element +" can enter.")
entered_people+=1
print("Next time please.")
Peter can enter. John can enter. Gary can enter. Amy can enter. IndexError: list index out of range