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

```
def median(series):
series=sorted(series)
length=len(series)
if length % 2 == 0:
first=series[(length / 2)]
second=series[(length / 2)-1]
average=(first + second)/2
return average
else:
if length==1:
return series[length-1]
else:
first=float((length+1))/2
return series[first-1]
```