Median


#1



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

It says "Oops, try again. median([1]) resulted in an error: object of type 'NoneType' has no len()"


i expected for it to print out the median.


def median(initList):
    newList = initList.sort()
    length = len(newList)
    newLength = length + 1
    place = newLength / 2
    if length < 2:
        return newList[0]
    elif length % 2 == 1:
        return newList[place-1]
    else:
        mean1 = newList[place]
        mean2 = newList[place-1]
        mean = (mean1 + mean2)/2.0
        return mean


#2

sort() will update the list for you, no need to store the result in a variable


#4

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