When I run the code, the following message pops up: median([6, 8, 12, 2, 23]) returned 12 instead of 8

Can someone help please?

```
def median(numbers):
sort = sorted(numbers)
length = len(numbers)
mid_index = length/2
total = 0
if length % 2 == 0:
mid_1 = mid_index
mid_2 = mid_index + 1
total = numbers[mid_1] + numbers[mid_2]
total = total/2.0
return total
else:
mid_index = int(mid_index+0.5)
total = numbers[mid_index]
return total
```