15/15 median, need help


#1



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


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

i don't know why it returned 0,can you please explain to me what is wrong with my code?
thanks


def median(numbers):
    tidy = sorted(numbers)
    if len(tidy) ==1:
        return tidy[0]
    elif len(tidy)%2 ==0:
        mid = len(tidy)/2
        mid_number = tidy[mid-1]/tidy[-mid]
        return mid_number
    else:
        mid = (len(tidy)//2)+1
        return tidy[mid]


#2

here:

mid_number = tidy[mid-1]/tidy[-mid]

what is this line suppose to do? And does it fit to use a division operator for this purpose?


#3

it supposes to get the number for the median.
the median located between the tidy[mid-1] and tidy[-mid], so i used division to get the median for the even number list.
is it wrong?


#4

if i have the following list (after sorting):

[4, 4, 5, 5]

the median is the sum of the middle values (4 and 5) divided by 2


#5

lol. I just realized my fault after seeing your reply, it is very embarrassing.
thanks a lot. :joy:


#6