Practice Makes Perfect 15. median
My code seems to fail on lists with an even number of elements. I get the error message: Oops, try again. median([4, 5, 5, 4]) returned 5 instead of 4.5
I realise there may be ways to tidy up the code, but it looks as though it should work. It actually runs well in Python 3.
Replace this line with your code. Do not remove the backticks that are above or below this line. def median(list): print(sorted(list)) if len(list) %2 == 0: return (list[int(len(list)/2)-1]+list[int(len(list)/2)])/2 else: return (list[int(len(list)/2)])