SyntaxErrorWhat is a SyntaxError?
A SyntaxError means Python could not read your code at all, so nothing ran. A missing colon, bracket or quote is the usual reason.
What SyntaxError means
SyntaxError: expected ':'Before running anything, Python reads the whole file and checks that it is written in valid Python. A SyntaxError means that check failed, so not a single line ran, not even the ones above the mistake.
The usual causes:
- A missing colon at the end of
if,for,while,deforelse. - A bracket or quote that was never closed.
print("hi"or"hello. =where==was meant, as inif score = 10:.
How to find it
Python shows the line with a ^ under the spot where it got confused. The real mistake is often there, or at the end of the line just above it, because an unclosed bracket only becomes a problem when the next line starts. Check that line for a missing :, ) or quote.
Run it: a missing colon
Press Run and read the error from the bottom up.
score = 12
if score > 10
print("High score!")
The scoreboard that never starts
This should print the best score and the number of games. Nothing runs at all. Fix it.
scores = [12, 30, 7]
print("Best:", max(scores)
print("Games:", len(scores))