15/15 Median Help


#1



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

The code below for 15/15 (calculating medians) is throwing up the following error:

File "python", line 7
else:
^
SyntaxError: invalid syntax

I am unable to figure out what is causing this and help would be appreciated
(by the way, I know it's counter-intuitive that I'm using array for length measurements but i doubt that would make a difference)


def median(array):
    ordered_list = sorted(array)
    
    if len(array) % 2 == 0:
        return (ordered_list[len(array) / 2] + (ordered_list[(len(array) / 2)-1]) / 2
    
    else:
        return ordered_list[(len(array)/2)-0.5]


#2

Just looking at the error you receiving, the problem is the line above:

return (ordered_list[len(array) / 2] + (ordered_list[(len(array) / 2)-1]) / 2

take a good look at all brackets, the ( bracket after return doesn't have a matching closing bracket

Now, this is just a step in the right direction, please take a moment to check your own code before posting again. Good luck!