15. median Please help to check my code!


#1



def median(lst):
    sorted(lst)
    if len(lst) % 2 == 0:
        med_num = (lst[len(lst)/2] + lst[len(lst)/2 - 1]) / 2.0
        return med_num
    else:
        return lst[len(lst)/2]

Error: 
Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5

Thank you!


#2

Hello

Add lst infront of sorted(lst) -
lst = sorted(lst)
I noticed that you used lst but never stated its value.
Hope that helps. Please let me know.


#3

Yeah, I got it. Thank you a lot!


#4

Hello

That's great news.
If you feel that your topic was solved, remember to mark it as such. Others might experience the same or similar errors.

Thanks


#5

Yes, I have done.
This is the first time I create a topic for asking solution here... LOL...


#6

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