NZEC error python(real quick help)

Life Universe

My code


nums = []

while len(nums)<5:
    nums.append(int(input()))
    
fourtwoindex = nums.index(42)

for i in range(fourtwoindex):
    print(nums[i])


I don’t get why it returns an error,when I test it on my own I get the exact same result as what is says I should get in the same order.

The input can have more than 5 numbers. You can use a try-except to read all of it, or much better, read until you read in a 42