Code academy python - median


#1



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


File "python", line 13
else:
^
SyntaxError: invalid syntax


I need help with my code, i dont understand why it says invalid syntax, sorry if its obvious i am new


def median(numbers):
    numbers.sort()
    if len(numbers) % 2 == 0:
        n = len(numbers) - 1
        n += len(numbers) + 1
        n /= 2
        return n
    else:
        if len(numbers) != 1:
            f = len(numbers) / 2
            f = 0.5 + f
        return f
    else:
        return numbers


#2

the order is always:

if
elif (zero, one or more elifs if you like)
else

you can't have mutliply else's, given else are all remaining cases


#3

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