15.median


#1



Hi,
I tried this code but it seems to not work, so what is the problem in it?, and what does that error means?
Thanks in advance


Replace this line with your code.


#2

A median is not an average, so for the else case, I would simply,

return x[y]

In the if clause, you are calculating the average of only two values, but it is an average, so semantically your variable name is okay. I would simply,

return ___

Be sure to set the numerator as a float()

return float( ... ) / 2

#3

I know it's not an average, it's just the name.
I tried to set the results to float, but still have the same problem which seems in line 2 "x.sorted()'


#4

For in place sort,

x.sort()

To sort only a copy, not the actual list,

y = sorted(x)

#5

ahaaa, that worked.
Thanks for the great help :")


#6

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