Help! 15 of 15


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096#


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


def median(stats):
    analysed=[]
    median_list=0
    for i in stats:
        analysed.append(i)
        sorted(analysed)
    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])


#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.


#3

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


#4

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