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


#1

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

def median(x):
new_list = []
for i in x:
new_list.append(sorted(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
else:
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


#2

can’t run that.


#3

image


#4

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