Median: syntax error for "else:"?


#1

why am I receiving an error for the else command?

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

def median(n):
    a = sorted(n)
    if len(a) % 2 == 0:
        m1 = len(a)/2
        m2 = len(a)/2 - 1
    average = (a[m1] + a[m2]) / 2.0
    else:
        average = a[len(a) / 2)]
    return average

#2

the line above is wrongly indented.

else can only be after if statement or else if statement


#3

lol....thanks, not sure how I missed that... also found the other mistake too....thanks again


#4

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