Median - help please!


#1

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

Hi all

I can't understand why I get the following error message when I run the code below:

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

import math
def median(med):
    m = 0
    l = len(med)
    j = l/2
    v = med.sort()
    if l % 2 == 0:
        m = (float(v[j]) + float(v[j - 1]) / 2.0
    else:
        m = float(v[math.floor(j)])
    return m

Many thanks in advance.

#2

this line:

m = (float(v[j]) + float(v[j - 1]) / 2.0

take a look at the numbers of brackets you have, they don't match.


#3

Many thanks, problem solved!