15. Median


I can't figure out what's wrong with my code; when the number of elements in the sequence is even, the median rounds up to a whole number instead of a decimal like it should :frowning:

def median(sequence):
    sort = sorted(sequence)
    if len(sequence) % 2 == 0:
        return (( sort[len(sort)/2] + sort[(len(sort)/2)+1]) / 2.0)
        return sort[len(sort)/2]

Replace this line with your code.


Try going downwards, and not upwards.


Thanks so much! You're a lifesaver


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