I'm new to programming. I'm trying to write a program with 3 lists. There are no while loops in the code (see below).
I tried saving the user's answers in a list called 'user_answers'. The for loop is supposed to loop only 5 times (which is the length of the list), but it seems like I got an infinite loop instead. Any insight on how to fix this?
def user_answer():
user_answers=[0, 0, 0, 0, 0]
print('\n')
for i in range (len(user_answers)):
print('\nPlease enter the answer to question', i+1, ':', sep=' ', end='')
user_answers[i]=input()
return user_answer()
return user_answer()is calling the function recursively without any conditional to stop it. In short, your function is calling itself infinitely. It should bereturn user_answers.