Still returning 4 instead of 4.5 median


#1



Replace this line with your code. 
def median(r):
    r=sorted(r)
    t=len(r)
    if t%2==0:
        p=(t/2)
        q=(t/2)-1
        s=(r[p]+r[q])/2
        return s
    
    else:
        if t==1:
            return r[t-1]
        else:
            p=(t+1)/2
            return r[p-1]


#2

In Python 2.7.x this will be an integer. We must declare it a float.

s = float( ... ) / 2

The ... is filler. Replace with your code.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.