Lists challenge - code problem [solved]

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?

It would be much easier to analyze your code if you would render it as actual Python by including the indentations. You can do so by using the </> icon in the menu bar that appears atop the text box when you type.

The traceback will indicate where the list is being accessed, and approximately
where the error is occurring.

My guess is it has something to do with that. The SCT may be using its own test sequence that is shorter than yours.