I wrote this code on Jupyter notebook so that I could iterate through and get it working properly. I then c/p into codecademy and it doesn't respond the same way. I get the error:
"Oops, try again. median([4, 5, 5, 4]) returned 4.0 instead of 4.5"
While when I input the same list into Jupyter it returns the correct answer (4.5)
Here is my code:
def median(numbers): numbers = sorted(numbers) me = 0 while me ==0: if len(numbers) == 1: me= float(numbers) return (me) elif len(numbers) ==2: me = float((numbers+numbers)/2) return (me) elif len(numbers) > 2: numbers.pop(0) numbers.pop(-1) print (me)
Any idea why this might be happening?