Oops, try again. median([4, 5, 5, 4]) returned 4 instead of 4.5

I cannot figure out why my code is not calculating the average correctly.

```
def median(x):
average = 0
middle = len(x) / 2
y = sorted(x)
if len(x) % 2 == 0:
average = y[middle - 1] + y[middle]
average = average / 2
return average
else:
return y[middle]
```