What am I getting this error?

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

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

what error? Please include the error in your topic

If I had to guess, I would say the problem is on this line:

    new_lst=((lst[(lst /2) -1] + lst[lst/2])

you are missing a closing bracket. the first opening bracket on this line is never closed

1 Like

Sorry, line 4 is the error (return new_lst/2), I keep getting the syntaxError:invalid syntax

Stetim’s answer covers that. Often, if there is a missing bracket, it’ll be the next line that throws the error.

1 Like