Help! 15 of 15


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

def median(stats):
    for i in stats:
    if len(analysed)%2==0:
         return (analysed[(len(analysed)-1)/2]+analysed[(len(analysed)/2)])/2.0

    if len(analysed)%2==1:
        return float(analysed[(len(analysed)-1)/2])


You've got a really long expression there, it would be easier to debug if you created variables for the middle or middle two, the length, and then determined the median from that. If the result comes out wrong all you have to do is to look at those values and see which one isn't right and then look at how that incorrect value was produced while keeping in mind how it should have been produced.


Thank you, it helped a lot!
I managed to find the error.


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