This forum is now read-only. Please use our new forums! Go to forums
banner
Close banner
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
Answer 52c23d26282ae3e671000710
0 votes
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.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency