Python F&Q 汇总
python-if-else-SyntaxError:invalid syntax 问题
if elif and else must immediately follow the end of the if block, or Python will assume that the block has closed without them.
<--- this line must be indented at the same level as the `pass`
In your code, the interpreter finishes the if block when the indentation, so the elif and the else aren’t associated with it. They are thus being understood as standalone statements, which doesn’t make sense.