Median


#1



Help me ..


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096#


Oops, try again. median([4, 5, 5, 4]) returned 7.0 instead of 4.5


def median(n):
a = sorted(n)
if len(a) % 2 == 0:
m1 = len(a)/2
m2 = len(a)/2 - 1
average = a[m1] + a[m2] / 2.0
else:
average = a[len(a) / 2]
return average

`


#2

here:

average = a[m1] + a[m2] / 2.0

order of math operations, division is before sum. Use parentheses, you first want to add numbers together first


#3

Yes it is a fault in order of math operations..i have executed the code ..Thank you


#4

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