The code is made to work with a specific amount of items in the list
questions
The error happens because the list only has an item at index 0.
When it goes through the
while True
loop the first time
n
has the value 0.
questions[n]
returns the first item of the list.
it continues to
n += 1
, n now has the value of 1.
It goes through the while
True loop
again and tries to call
questions[n]
to get the next item at index 1.
Because there isn't another item it gives the
IndexError: list index out of range
error.