Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...