# Median doesn't work for [1]

#1

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

I don't understand why this fails or why it doesn't like len().

``````def median(series):
s = series.sort
m = len(s) / 2
if len(s) % 2 == 0:
x = (float(s[m]) + float(s[m-1])) / 2.0
else:
x = s[int(m)]
return x``````

#2

for resolve that error

``s = series.sort``

in here, you get a method, not call a method,
this work is such as create that function with another name or create other way to access that.

for call a method and get results should use `()` after name of method. --> `series.sort()`

#3
``````def median(x):
x.sort()
if len(x) % 2 == 0:
return (x[int(len(x)/2-1)] + x[int(len(x)/2)]) / 2.0
else:
return x[int(len(x)/2+0.5)]``````

Not very beautiful, but the math is right. It works with or without the +0.5 in the last line, as far as Codecademy is concerned... IDLE might complain one way or the other.
1. Sort x . Or, in your case, replace "x" with "series."
2. "if" length of x is even, return the average of the middle two numbers.
3. "else" return the middle number