15. Median


My code is not working. Can anyone help me fix it?

def median(l):
if len(l)==1:
    return l[0]
if len(l) % 2 != 0:
    return l[len(l)/2]
    return (l[len(l)/2] + l[len(l)/2 - 1]) / 2.0

File “python”, line 4
SyntaxError: ‘return’ outside function
Please help


Correct the indentation so all the code is in the function block. Currently the only line in the block is,


From a practical point of view, l is not a very readable variable name since it looks so much like a 1. Recommend use a name of at least a letter that does not look like a number.