Take the 2-minute tour ×

I get an Invalid Syntax error for my code, but I have no idea why. My code should create a 2 dimensional list of zeroes and then change one of the zeros to a one, and check certain list values, to see if it will return the 1, or just zeros. I define a function that should return a list of the adjacent cell values, but for some reason the syntax error arises. Here is my code:

def test(x,y):
    spotX = [(x-1)%height,0,(x+1)%height]
    spotY = [(y-1)%height,0,(y+1)%height]
    val = []
    for a in range(3):
        for b in range(3):
            if a and b != 2:
    return val

The syntax error is that "return val" line.

share|improve this question
There's a missing ) at the end of val.append(newBoard[spotX[a]][spotY[b]] –  A. Rodas Mar 10 '13 at 4:15
FYI, syntax errors often get marked as being in a line or two after the actual error if the mistake is a missing delimiter (like )), becuase the interpreter will continue looking for that ) and find a return statement, or something that doesn't belong inside (). That's where it's upset, but not where you need to fix it. –  askewchan Mar 10 '13 at 4:32
add comment

closed as too localized by Michael Berkowski, David Robinson, Rohan, Inbar Rose, Łukasz 웃 L ツ Mar 10 '13 at 10:03


1 Answer

The reason the error is mentioning the return val line is because it believes that it is part of the append function, when actually you just forgot to close the bracket.

share|improve this answer
add comment
