15/15 - Codecademy vs Pycharm outcome


#1

For some reason this code words properly in Pycharm but not Codecademy. In Codecademy, it attempts to return a median of 4 instead of 4.5 for the list [4,4,5,5].

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096

def median(ulist):
slist = sorted(ulist)
items = 0
for i in slist:
    items += 1
if items % 2 == 1:
    indx = items / 2 + 0.5
    return slist[int(indx-1)]
else:
    indx = items / 2 
    sl1 = slist[int(indx-1)] 
    sl2 = slist[int(indx)]
    hmm = (sl1 + sl2) / 2
    return hmm

print('med',median([1,2,5,3,4]))
print('med',median([4,5,5,4]))

#2

Python2 and Python3 deal with division between ints differently