I was able to pass the problem with the following code:

def median(list):

new_list = sorted(list)

if len(new_list) % 2 != 0:

```
median = new_list[len(new_list)/2]
return median
```

else:

```
index_1 = len(new_list)/2
median_1 = new_list[index_1]
index_2 = index_1 - 1
median_2 = new_list[index_2]
median = (median_1 + median_2) / 2.
return median
```

However, I do not understand why my original code was not working:

def median(list):

new_list = sorted(list)

if len(new_list) % 2 != 0:

```
median = new_list[len(new_list)/2]
return median
```

else:

```
index_1 = new_list[len(new_list)/2]
index_2 = new_list[len(((new_list)/2)-1)]
median = (index_1 + index_2) / 2.
return median
```

I have the following error for the index_2 line:

TypeError: unsupported operand type(s) for /: ‘list’ and ‘int’

Could something explain me why Python cannot run this/this error ? I don’t see why it considers the len part as a list (I might be wrong on this). To me, the functioning code is similar.

Thank you