Getting an invalid syntax error on an elif statement


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096

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):
    x=sorted(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]
    else:
        return x[((len(x)-1)//2)+1]
median([3,54,1])


#2

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]


#3

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