I can't figure out why my code is returning with this:
Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5
def median(nums): n = sorted(nums) print n, length = len(n) print length, for x in n: if length % 2 == 1: return n[(length + 1) / 2 - 1] else: upper = n[(length + 2) / 2] lower = n[(length) / 2] end = ((upper + lower) / 2.0) return end
I've sseen someone ask the same question but I didn't know how to translate the answer to my code.