Median


#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

Replace this line with your code.

def median(x):
    x=x.sort()
    b=len(x)    
    if b%2==0:
        a=(x[b/2]+x[b/2-1])/2.0
    else:
        a=x[b/2]
    return a

Hi! I don't understand what is wrong with my code. Maybe I missid something? Help me please


#2

sort() will return a sorted listed of the current variable, so you don't need to store it (sort updates the current variable). so you can just do:

x.sort()

#3

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