SyntaxError or NameError

  • Python

You may see

SyntaxError: expected ':'
SyntaxError: '(' was never closed
NameError: name 'prnt' is not defined. Did you mean: 'print'?
SyntaxError: invalid syntax

Why it happens

  • A missing : after if, for, while, def or else.
  • An open bracket or quote, often on the line above.
  • A misspelt name.

How to fix it

  1. Look at the line with the ^ and the one above it.
  2. Close every bracket and quote.
  3. Copy the block again with the Copy button if unsure.

It worked if: The program starts.

Seen in a real run (some lines are close variants of it). Produced with Python 3.13 on Windows.

Didn't help? Search another error or ask us.