Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5
My code seems to work fine, as in this case(4,5,5,4) it actually returns 4.5, but the same error message as above keeps show up.
I don't understand what is wrong with my code.
num = [int(n) for n in raw_input("Enter numbers divided by spaces:").split()] nums = sorted(num) def median(nums): length = len(nums) if length %2 != 0: n = (length-1)/2 k = nums[n] else: n = length/2 k = (nums[n-1] + nums[n]) / 2.0 return k print(median(nums))