15/15 Returning 4 instead of 4.5


#1

I wrote my code out and it keeps telling me that with the list [4,5,5,4] returns a value of 4 instead of 4.5. I did the math that my code should be doing, and it should be returning 4.5. I went and plugged my code into Visual Studio and I got 4.5. But Codecademy is getting 4. I'm at a loss.

def median(original):
    newList = sorted(original)
    result = 0
    varA = int(len(newList) / 2 - 1)
    varB = int(varA + 1)
    if len(newList) < 2:
        result = newList[0]
    elif len(newList) % 2 == 0:
        result = (newList[varA] + newList[varB]) / 2
    else:
        result = newList[varB]
    return result

#2

In python 2 the division operator will return the number of decimal points given in the arguments.

Try dividing by 2.0


#3

Bingo. Thanks for the tip.


#4

works in 3.1 as well