Blockquote

def median(lst):

sorted_list = sorted(lst)

if len(sorted_list) % 2 != 0:

#odd number of elements

index = len(sorted_list)//2

return sorted_list[index]

elif len(sorted_list) % 2 == 0:

#even no. of elements

index_1 = len(sorted_list)/2 - 1

index_2 = len(sorted_list)/2

mean = (sorted_list[index_1] + sorted_list[index_2])/2.0

return mean

print median([2, 4, 5, 9])

This code was given as a solution for the ‘Median’ and works fine on the website.

When I use it in my Python IDLE 3.6.2 it gives an error message.

It seems, that this version returns a float even when dividing with an integer.

The index_1 and index_2 variables have to be converted to an integer.

index_1 = int(len(sorted_list)/2 - 1)

Is there an option in the Python IDLE to be set to guarantee a division by an integer returns an integer?