15/15 Median. Need Help with my code (and line of thinking)


To me, this seems like it should work but its returning [1] instead of 1.

def median(x):
new_list = []
for i in x:
print new_list
if len(new_list)%2==0:
first = new_list[len(new_list)/2]
second = new_list[(len(new_list)/2)-1]
avg = (first+second)/2
return avg
firstprime = new_list[(len(new_list)-1)/2]
return firstprime

print median([1,4,6,3,2,8,6,4,3,3,7])

Any help would be greatly appreciated


can’t run that.




This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.