#15 why doesnt the code work...?


Oops, try again. median([1]) resulted in an error: list index out of range

def median(numbers):
    if len(numbers)%2!=0:
    elif len(numbers)%2==0:
    return middle


now the error is -->Oops, try again. median([1, 34, 1, 6, 8, 0]) returned 5.5 instead of 3.5
the list doesnt sort, but I have written the number.sort() code.


Why would it work?
What steps is it supposed to carry out?
Is it doing those steps? How can you find out?

If you've identified that it doesn't sort (don't guess, find out) then how can you look up how sorting is done in python?


oh my god , I fixed it , I was writing the step by step, what would my code do for the error message's code and noticed, that (numbers[len(numbers)/2]-1) --> the "-1" is outside the "]" so I fixed it>> middle=(numbers[len(numbers)/2]+(numbers[len(numbers)/2-1]))/2.0, Thank you so much :slight_smile:


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