15/15 my code works everywhere except codeacademy, help please


#1



def median(lst):
st = sorted(lst)
if len(st)%2==1:
return st[(len(st)//2)]
else:
return ((st[((len(st)-1)//2)] + st[(len(st)//2)])/2)


for lst = [4,5,4,5] returns rigth value 4.5, but codeacademy writes :Oops, try again. median([4, 5, 5, 4]) returned 4 instead of 4.5




#2

Replaced 2 on 2.0 and now it works, unbelievable


#3

Python 2 sees this as an integer if the numerator is an integer.

Explicit float:

float(x[m - 1] + x[m]) / 2

#4

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