def median(lst):
srt_lst = sorted(lst)
cnt = len(srt_lst)
avg = round(cnt/2)
result = 0
e1 = 0
e2 = 0
if cnt % 2 == 0:
e1 = srt_lst[avg]
e2 = srt_lst[avg - 1]
result = (e1 + e2)/2
return result
else:
result = srt_lst[avg-1]
return result
print median([1,1,2])
When I run this on the python shell it runs fine, but on the site shell I get this error:
Oops, try again. Your code did not run to end. Check the console window for errors!
Traceback (most recent call last):
File "python", line 17, in <module>
File "python", line 14, in median
TypeError: list indices must be integers, not float