Getting an invalid syntax error on an elif statement


The elif statement is along the same indentation as the if statement above and the else below and has a colon. What's wrong about the syntax?

def median(x):
    print x
    if len(x)%2==0:
        return (x[((len(x)//2))-1]+x[(len(x)//2)/2
    elif len(x)==1:
        return x[0]
        return x[((len(x)-1)//2)+1]


Two things with your large return statement, you are missing a closing parenthesis before the + sign and you are missing a closing bracket at the very end of that return statement.

I'm guessing you want it to look something like this:
return (x[((len(x)//2))-1])+x[(len(x)//2)/2]


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