If和Else语句的语法错误 [英] syntax error for If and Else statements

查看:168
本文介绍了If和Else语句的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入图像描述hereOk,我刚开始学习python,我无法弄清楚为什么我的IF / Else语句在输入Else后仍然出现此错误:SyntaxError:unindent与任何外部缩进级别不匹配 。这是我的代码
如果x> 1000:
print('3')
else:

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不匹配任何外部缩进级别

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

以下是错误(以下链接)
错误
以下是解决方案:kind-af看起来很有趣,但即使If最初在第4列python将其注册为第0列,所以我不得不把我的其他:放在第0列(即使它看起来不对齐。感谢每一位帮助!!
解决方案

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

推荐答案

啊,IDLE。你试过把它输入shell,对吗?所以看起来像是

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

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

对吗?重点是,&g计算缩进时t;>> 不计算。事实上,就IDLE而言,if和else在同一列中不是。 :-( [它看到的缩进是0,8,4。]你必须启动 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.

这篇关于If和Else语句的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆