Median: Syntax error on the ELSE, of all things?


Why am I getting invalid syntax on the ELSE, of all things?

def median(list_of_things):
    if len(new_list)%2==0:
        return ((new_list[(len(new_list)/2)] * new_list[((len(new_list)/2)-1)])/2
        return new_list[(len(new_list)/2)]


The error is likely before the else. Your math looks a little bit off, as well.

May I suggest solving it longhand before attempting to refactor into single returns. There is a lot of repetition in this that could be pared down considerably.


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