Hi everyone! After a lot of trying and testing I got a working code to take the median of a list, regardless if it is an even or oneven number. However it still doesn't run in Codeacademy as it runs on Atom.
Does anybody know what happens there? Any tips are welcome of course! Thanks!
It gives the error: Oops, try again. median([4, 5, 5, 4]) returned 4 instead of 4.5. But I tested it in Atom and it does give the 4.5 as needed.
def median(x): lijst = sorted(x) if len(x) % 2 == 1: return lijst[int((len(x)/2))] else: return (lijst[(int((len(lijst)-1)/2))]+lijst[(int(len(lijst)/2))])/2