This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by fjk7291
over 10 years

I keep getting invalid syntax errors for colons

I recently got this error message:

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

I’ve gotten it a couple of times for if statements, and then reset code and type the same thing and it works Am I doing something wrong?

Answer 529958d7abf8211d68005137

1 vote

Permalink

can’t tell without the code, but perhaps the error was in the line above in a way that this line didn’t make sense

points
Submitted by Jonatan
over 10 years

Answer 52c23d26282ae3e671000710

0 votes

Permalink

Again without the code we can only guess.

Generally; make sure the line before is indented one level further than the else. Make sure the line before is a valid statement - and not blank, and not just the preceding if/elif. And make sure the else: line is indented to line up with the preceding if/elif.

points
Submitted by Adam Fawns
over 10 years