Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

python - syntax error for If and Else statements

enter image description hereOk, I am just starting to learn python, and I can't figure out why my IF/Else statement keeps getting this error after I enter Else: "SyntaxError: unindent does not match any outer indentation level". Here is my code if x>1000: print('3') else:

SyntaxError:SyntaxError: unindent does not match any outer indentation level

the if and else are on the same column, so I am not sure whats happening?

Here is the error (link below) Error Here was the solution: kind-af funny looking, but even though If was initially on column 4 python registered it as column 0, so I had to put my else: on column 0 (even though it didn't look aligned. THANKS EVERYBODY FOR THE HELP!! Solution

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ah, IDLE. You have tried to enter this into shell, right? So the thing looks like

>>> if x > 1000:
        print(3)
    else:

right? The point is, >>> doesn't count when calculating indents. So in fact if and else are not in the same column as far as IDLE is concerned. :-( [The indents it sees are 0, 8, 4.] You have to start the else: flush completely to the left margin.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...