15. Median


Hi! I'm sure I'm missing something silly, but getting a syntax error at line 5 - else:
Any ideas what I'm doing wrong?

def median(numbers):
    sort = sorted(numbers)
    if len(sort) % 2 == 0:
        return (sort[len(sort)/2] + (sort[len(sort)/2-1]) / 2.0
        return sort[len(sort)/2]
numbers = [4,5,5,4]

print median(numbers)


Bracket error on line 4.

... + ( ...


Argh..!! Of course..! Thank you :slight_smile:


Recall that the error indicator shows where parsiing ceased due to unexpected token or expression. The error will be somewhere before that point.


That's really helpful, thanks! I got myself stuck on the "else: invalid syntax" message and didn't look properly at the line before that.


Hey you also forgot a big bracket around your addition in total, "order of operation rule" ;* or / is covered before + or -


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