15.median excercise error


#1



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


Oops, try again. median([6, 8, 12, 2, 23]) returned 7.0 instead of 8


def median(val):
    val.sort()
    mid=len(val)/2
    if mid%2!=0:
        mid=mid-0.5
        mid=int(mid)
        new=val[mid]
    else:
        mid=int(mid)
        new=((val[mid-1]+val[mid])/2.0)
    return new


#2

here:

mid=mid-0.5

why subtract 0.5? dividing an integer by integer results in a integer, so i don't see why you would subtract 0.5


#3

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