15.median


#1



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


I dont realy know whats wrong, please help!

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


def median(lst):
    lst1=lst.sort()
    med=0
    if len(lst1)%2==0:
        med=((lst1[(len(lst1)/2)-1])+lst1[len(lst1)/2])/2
    else:
        med=lst1[(len(lst1)-1)/2]
    return med


#2

sort() will update the list for you, don't store it in a variable.


#3

def median(lst):
lst=lst.sort()
med=0
if len(lst)%2==0:
med=((lst[(len(lst)/2)-1])+lst[len(lst)/2])/2
else:
med=lst[(len(lst)-1)/2]
return med

even so, it doesen't work, same eror: 'Oops, try again. median([1]) resulted in an error: object of type 'NoneType' has no len() '


#4

but you didn't make the change i suggested? you still store the sorted list in lst, you shouldn't. sort() will update the list for you


#5

ok, got it know. Thanks!


#6