Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5
I know my else statement is messed up, but right now I'm more worried about why my elif statement (the one that runs if the length of the sequence is even) is not working. You know, I got nothing but straight A's in AP Calculus and I love a good challenge, but this is seriously making me question my ability to do simple math.
def median(num): sorted(num) middle = 0 if len(num) == 1: return num[middle] elif len(num) % 2 == 0: middle = len(num)/2 middle2 = middle-1 subaverage = num[middle] + num[middle2] average = subaverage/2.0 return average else: middle = len(num)/2.0 return num[middle-1]