15.Median problems



On my compiler (not in codecademy) everything is ok, but here i have some problems:

Oops, try again. median([4, 5, 5, 4]) returned 4 instead of 4.5

returns the median of a row

def median(x):
    if len(x)%2!=0:
    return med


on your computer you might have python3, and codecademy has python2. There is a fundamental difference in this python version, python3:

5 + 4 / 2 = 4.5

in python2 however the number get floored:

5 + 4 / 2 = 4

you can solve this problem by using float() or divide by a float (2 is the same as 2.0, but then you get a floating number as result, not a integer)


Thank you so much! I didn't know that :frowning:


in python3 you can mimic python2 behavior:

5 + 4 // 2 = 4

by using //, anyway, python2 and 3 have some differences, you might want to google them, otherwise you might come across weird errors when working on your computer, the most important one, in python2 you can do:

print "something"

in 3 you have to use brackets:


oh, and raw_input no longer exist in 3, it is now input.


I heard about input () between python 2. and python 3.
But did not know that codecademy uses python 2.
And every time ask myself why I do not need any parentheless in codecademy