It is asking for a list that has an odd number of inputs, then to return the middle value. This is coded under the else: statement. Can someone explain how that code works? It appears to me that the code would return “lst[2.5]”, which can’t be indexed, and not “lst[2]”, which is the middle index value.

def middle_element(lst):

if len(lst) % 2 == 0:

sum = lst[int(len(lst)/2)] + lst[int(len(lst)/2) - 1]

return sum / 2

else:

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