Hi all, I am receiving the following error message: Oops, try again. median([6, 8, 12, 2, 23]) returned 6 instead of 8
the math is correct and I don't find a formal error in the code. Although from the error message I see that the code must have an error under the else loop, I am unable to identify the error, any ideas?
def median(numbers): numbers.sort() if len(numbers) % 2 == 0: middle = len(numbers) / 2 median = ((numbers[middle] + (numbers[middle - 1])) / 2.0) elif len(numbers) == 1: median = 1 else: middle = int((len(numbers) / 2) - 0.5) print middle median = numbers[middle] return median