15/15 I have no idea what's the problem here


#1
def median(lista):
lista = sorted(lista)
if len(lista) % 2 == 0:
    #EVEN
    median_number = (lista[(len(lista))/2] + \
                    lista[((len(lista))/2)-1]) / 2.0
else:
    #ODD
    median_number = lista[((len(lista)-1)/2)
return median_number

#2

You are probably getting an error with test case like median([4,5,4,5]) and yours returns 4 instead of 4.5? I did the same mistake at first and the problem is this median_number is not registered as float number in the first place. So when you divide 9 by 2, you get 4 instead of 4.5. You can try float((lista[(len(lista))/2] + \ lista[((len(lista))/2)-1]) / 2 .


#3

Actually the error message is this:

File "python", line 10
    return median_number
         ^
SyntaxError: invalid syntax

#4

About the FLOAT, can I initialize the variable like this?

median_number = float()

#5

There is probably a paranthesis missing at line 10. Sweep your code and be careful about syntax.


#6

You are missing the index ] paranthesis before / 2.0 to be exact. @42piratas