Hi, I have a f question. So I have came up with this function:

def middle_element(lst):

if len(lst)%2 == 1:

return lst[int((len(lst)/2))]

if len(lst)%2 == 0:

half = int(len(lst)/2)

first_half= lst[:half]

second_half = lst[half:]

mdl_avg = (first_half[2] + second_half[0])/2

return mdl_avg

Now, I know the function is weird and not ideal at all. But I don’t actually understand what results in the error I get:

When I print(middle_element([5, 2, -10, -4, 4, 5])) I do get result -7.0 as supposed and I do not get any error in the console on the right, but the website tells me at the bottom “list index out of range” and marks excercise as failed. Why?