Why do I get this syntax error?

def middle_element(lst):
  if len(lst) % 2 ==0:
       new_lst=((lst[(lst /2) -1]) + lst[lst/2])
  return new_lst/2
  return lst[(len(lst)+1)/2]

Why do I keep getting a syntax error on line 5?

the lines with return have the wrong indentation

also, I think the lst you are using as part of the index should actually be len(lst) (on the 3rd line)


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.