Median


#1

I tried this code on repl.it and it works. Here it says:
'median([4, 5, 5, 4]) returned 4 instead of 4.5’
pls help

  noofel= len(numbers)
  sort = sorted(numbers)
  med = 0
  if noofel%2 == 0:
    med = (sort[int((noofel-1)/2)] + sort[int((noofel)/2)])/2
  else:
    med = sort[int((noofel-1)/2)]
  return med

#2

the problem is that a division which involves two integers:

print 9 / 2 # 4

will be rounded down (floor) to nearest integer. To overcome this problem, this division should involve a float

which version of python did you use on repl.it? in python3, changes where made to division behavior.


#3

on repl.it I use python 3


#4

in python3, changes to division behavior where made, to make it work on python2 (which codecademy uses) the division should involve a float to prevent the rounding down


#5

ok. got it. thank you


#6