15. median


#1

def median(l):
sorted(l)

if len(l)%2==0:

    a=l[(len(l)/2)-1]
    b=l[(len(l)/2)]
    med=float((a+b)/2)
else:
    a=(len(l)/2) - 1/2
    med=l[a]
return med

median([1])

could you tell me what is the problem in my code


15. median
#2

you sort the list, where do you store the sorted list?

What is the error message?


#3

6 posts were split to a new topic: [solved] median


#4

What could be the error here?

def grades_std_deviation(grades):
variance = grades_variance(grades)
result = variance ** 0.5
return result

print grades_std_deviation(grades)

ERROR:

Oops, try again. grades_std_deviation(9.6543209877) raised an error: 'float' object is not iterable


#5

This is a completely different exercise, please make a new topic. This topic is for helping vids96 with his median problem


#6

The error here is that [4, 5, 5, 4] is returning 5 instead of 4.5


#7

That is one of the two questions i asked, what about the other one:


#8

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