I'm getting a syntax error where I believe my syntax is correct


I’m really confused.

If I have

def median(numlist):
  print numlist

It all works out, but the second I do anything with the numlist, such as…

def median(numlist):
  if len(numlist) % 2 == 0:
    print "It's even"
    #Note: (len(numlist) / 2) should give me one integer to the right of the halfway point

And THIS returns

  File "python", line 10
SyntaxError: invalid syntax

However, the line median([1,2,3,4,5,6,7,8,9,10]) is the exact same in the two cases. Is my syntax really incorrect if it worked with the barebones test above?


The code you posted (middle code box) is syntactically valid:


Do you know why it isn’t running on codecademy then? Should I report it as a bug?

Edit: OH

I am getting the error only when this line is in the code

print numlist[((len(numlist) / 2) - 1)

I see where I went wrong here, but I wonder why python pointed below this and said the syntax was invalid?


You could have written other things that involved closing off the braces. It pointed where things stopped making sense, not at the mistake, python has no idea what you meant.


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