Median


#1


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


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


def median(numbers):
    sort_list = sorted(numbers)
    list_length = len(numbers)
    median = 0
    middle = 0
    if list_length == 1:
        median = numbers[0]
    elif list_length/2 != 0:
        median = sort_list[(list_length -1)/2]
    else:
        middle1 = list_length/2
        middle2 = middle1 - 1
        median = (sort_list[int(middle1)] + \
        sort_list[int(middle2)]) /float(2)
    return median


#2

dividing an integer by an integer results in a integer, you will need to use float somehow


#3

Sorry, I don't think I understand - where am I dividing an integer by an integer?


#4

my fault, this error is 9 out of 10 caused by what i suggested, you are one out of 10

for [4, 5, 5, 4], your elif condition will evaluate to true, so elif will run (and not else), is this desired?


#5

Thank you very much, I understand now! :relaxed:


#6