Median: Else: Syntax Error


#1

Python > Practice Makes Perfect > Median

I get this message when I submit my code:

Oops, try again. Your code did not run to end. Check the console window for errors!

And the console says::

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

I can't figure out what the problem is with using else: here.

def median(a):
    seq = sorted(a)
    if len(seq) == 1:
        median = seq[0]
    elif len(seq) % 2 == 0:
        median = float(((seq[len(seq)/2] + seq[(len(seq)/2)-1])/2)
    else:
        median = int(ses[len(seq)/2])
    return median

Any light anyone can shed would be much appreciated.

Cheers.


#2

It's still expecting a closing parenthesis


#3

Many thanks ionatan.


#4

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