15. median. help please


My code works well when the list has an uneven number of terms, but there is a problem when there are an even number of terms. Could you please help me find what's wrong?

def median(n):
    n = sorted(n)
    if (len(n)%2) == 0:
        a = ( (n[(len(n)/2)]) + (n[((len(n)/2))+1]) ) /2
        return a 
        b = (int(n[(len(n)/2)]))
        return b

Replace this line with your code.


the problem for a even list is that a integer + integer divided by a integer (2) gives a integer as result. The number gets floored so to say

You need a float output, use float() or divide by a float (2.0)