Oops, try again. median([4, 5, 5, 4]) returned 4 instead of 4.5
But when I run it in Spyder (the IDE I use), it returns 4.5
Am I missing something? Why is it not running correctly in Codecademy?
Full disclosure, I know that my code is probably really ugly and possibly inefficient, but it returns the correct answers for me.
def iseven(number): if number%2==0: return True else: return False def median(nums): nums==nums.sort() if iseven(len(nums))==True: index1=((len(nums)/2)-1) index2=index1+1 return (nums[int(index1)]+nums[int(index2)])/2 elif iseven(len(nums))==False: return nums[int(((len(nums)/2)-.5))]