```
Traceback (most recent call last):
File "python", line 13, in <module>
File "python", line 3, in median
TypeError: unsupported operand type(s) for %: 'list' and 'int'
```

Line 3 attempts to take a modulo of a list. I suspect you meant to write,

`if len(numbers) % 2:`

Note that I left off the `== 1`

. A non-zero quantity will evaluate to `True`

in a conditional expression. Either form is okay, but I prefer the `truthy`

version above.

Still testing...

New error

median([1]) returned 0 instead of 1

Consider your list...

```
a = [6,9,4,1,2,3,1,6,7,4,4,4,1]
a.sort()
print a
# [1, 1, 1, 2, 3, 4, 4, 4, 4, 6, 6, 7, 9]
# ^
# median
```

Your code returns `6`

.

```
first_middle = (len(numbers) / 2 - 1)
print first_middle # 5
second_middle = (len(numbers) / 2 + 1)
print second_middle # 7
```

See the difference between these two? `2`

. They need to be adjacent (difference of `1`

).

Still testing...

Another error.

Traceback (most recent call last):

File "python", line 16, in

File "python", line 15, in median

AttributeError: 'builtin_function_or_method' object has no attribute 'numbers'

`middle = len.numbers / 2`

I'm certain you meant to write,

`middle = len(numbers) / 2`

Still getting this error...

median([1]) returned 0 instead of 1

The line,

`return middle`

is returning the length divided by 2 rather than the value at that index.

`return numbers[middle]`

Now we get this error,

median([4, 5, 5, 4]) returned 5 instead of 4.5

This boils down to two minor errors in the code.

- The odd length case is returning the even length median
- The median being returned is the average of the indices, not the values at those indices.

I've simplified the code for clarity, and now have all the issues ironed out...

```
def median(numbers):
numbers = sorted(numbers)
n = len(numbers) / 2
if len(numbers) % 2:
return numbers[n]
else:
return float(numbers[n - 1] + numbers[n]) / 2
print median([6,9,4,1,2,3,1,6,7,4,4,4,1]) # 4
print median([6, 8, 12, 2, 23]) # 8
```