15. Median Error: median([1]) returned [] instead of 1


def median(lst):
    if len(lst)%2==0:
        return (first,second)
        return (mid)


for lists with a odd numbers of items the length divided by 2 gives the index you need for the middle item


Thank you.
But i can't get this one: median([4, 5, 5, 4]) returned 5.0 instead of 4.5
there are two numbers in the middle (5 and 5), so there is the question
Why it should return 4.5 instead of 5?


from the information of the exercise:

The median is the middle number in a sorted sequence of numbers

look at the word i made bold, rather important, so [4,5,5,4] would be [4,4,5,5] after being sorted, then the two middle numbers are 4 and 5

@terapro42417, i am helping you, don't go hijack someone else his topic, it is against the guidelines, and you won't be helped faster.


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