15/15 help!


#1

I have tried everything. What is my code missing?

def median(numbers):
sortlist = sorted(numbers)
lenlist = len(sortlist)
halflist = (lenlist - 1) // 2
if lenlist == 1:
return sortlist[len(sortlist)-1]
elif lenlist % 2 == 0:
return ((sortlist[halflist] + 1) + sortlist[halflist]) / 2.0
else:
return sortlist[halflist]


#2

I got it now :smile:

def median(numbers):
sortlist = sorted(numbers)
lenlist = len(sortlist)
halflist = (lenlist - 1) // 2
if lenlist == 1:
return sortlist[len(sortlist)-1]
elif lenlist % 2 == 0:
return ((sortlist[halflist + 1]) + sortlist[halflist]) / 2.0
else:
return sortlist[halflist]