My function returns (double the value of the element at index of lst and returns the new list with the doubled value) only if index is not too big.

When I click run it returns the doubled value in the new list but this comment is added to the bottom of the screen

“Make sure to define what should happen if index is too big!”

I click SOLUTION and get this code

def double_index(lst, index):

if index < len(lst):

lst[index] = lst[index] * 2

return lst

My code is excessive and overthought

but why do I keep getting this error

“Make sure to define what should happen if index is too big”

def double_index(lst, index):

length = len(lst)

if index == 100:

return “index is too big!”

elif index > 100:

return “index is too big!”

elif length < index:

return “index is too big!”

else:

value = lst[index] * 2

beginning = lst[0:index]

end = lst[index+1:]

lst =

lst = (beginning)

lst.append(value)

lst = (lst + end)

return lst