15/15: Just don't know why my code isn't working


This was my solution:

def median(numbers):
    num_list = sorted(numbers)
    for i in numbers:
        if (len(num_list) % 2 == 0):
            i = len(num_list) / 2
            j = k - 1
            median = (num_list[i] + num_list(j)) / 2
        elif (len(num_list) % 2 != 0):
            i = (len(num_list) + 1) / 2
            median = num_list[i]
            median = num_list[0]
    return median

but I got this error: > Oops, try again. median([1]) resulted in an error: list index out of range

please, what am I doing wrong, I'm confused!


Have you tried it without the for loop? There may be some error with the rest but I can't think of any way it would help. Also, I think you only need one if/else (mine does, not sure how yours would work)


couple of things i noticed
under your first if statement, you have num_list(j) instead of [j]
under your elif, the len(num_list) + 1 is not necessary (specifically the +1)
there are only 2 more things wrong and they're both in your first if statement, but you shouldn't have too much trouble figuring those out after you've taken care of the other things.