This error says that your program tried to access element of the list that does not exist.

If our list is `num_list = [1]`

and, for example, we try to get value of `num_list[2]`

this error will appear.

Let's see what happens in your code, we are interested in lines where you are exctracting values from your list:

```
oddmidposition= (length+1)/2
evenlowmidvalue= numlist[(length/2)-1]
evenhighmidvalue= numlist[(length/2)+1]
oddmidposition= (length+1)/2
```

What happens when length of our list is `1`

?

```
evenlowmidvalue= numlist[(length/2)-1] = numlist[-1]
evenhighmidvalue= numlist[(length/2)+1] = numlist[1]
oddmidposition= (length+1)/2 = 1
```

First index (`numlist[-1]`

) is not a problem, this means the same as `numlist[len(numlist) - 1]`

.

Second index is incorrect.

Third value is incorrect, it should be `0`

. To get median where length of the list is odd you should use this formula:

`oddmidposition = length / 2`

How to fix the problem with the second index?

Well, you can calculate indexes and retrieve data when you are sure that these values exists:

```
def median(numlist):
#Sortlist
sorted(numlist)
#Determine the length
length = len(numlist)
#Determine the mid position assuming odd number of elements
oddmidposition = length / 2
print oddmidposition
#Determine the low mid value assuming even number of elements
evenlowmidvalue= (length/2)-1
#Determine the high mid value assuming even number of elements
evenhighmidvalue= (length/2)+1
#Determine if odd or even
if length% 2 == 0:
#If even return the average of the two mid numbers
return 0.5*(numlist[evenlowmidvalue]+numlist[evenhighmidvalue])
#If odd return the middle item in the center of the array
else:
return numlist[oddmidposition]
```

But there is still one more problem to solve. Think again about the way to calculate the median when length of the list is even.

You have to change this line:

`evenhighmidvalue= numlist[(length/2)+1]`

Just think about it for a while.