I'm using Python 3 on my local machine to test some things out. My code gives me 4.5 as it should (18 / 4 = 4.5) I've tried several other list of numbers, all give me back the expected results.
However, when I try to convert this over the Python 2, I get 4 OK, I'll try adding a float to the sum(numbers) / index. That comes back as 4.0.
I'm sure I'm missing something quite easy that would make this come back as 4.5, as expected. Any suggestions?
def median(numbers): index = len(numbers) numbers.sort() if index % 2 == 0: print(sum(numbers) / index) else: index = int((index - 1) / 2) print(numbers[index]) median([4, 5, 5, 4])