>>> if temp > 60 < 75:
print 'just right'
else:
文件“”,第 3 行 else: ^ 这是出现的错误 ---> IndentationError: unindent does not match any external indentation level
一旦我按下回车,它就会出现,我不知道如何修复它,对不起,我知道这可能是一个非常愚蠢的问题,但我才刚刚开始,因此是非常基本的代码和错误。
>>> if temp > 60 < 75:
print 'just right'
else:
文件“”,第 3 行 else: ^ 这是出现的错误 ---> IndentationError: unindent does not match any external indentation level
一旦我按下回车,它就会出现,我不知道如何修复它,对不起,我知道这可能是一个非常愚蠢的问题,但我才刚刚开始,因此是非常基本的代码和错误。
首先,您应该使用:
if temp > 60 and temp < 75:
或者:
if 60 < temp < 75:
一旦你解决了这个问题,请确保你遵循 Python 的缩进指南。当您不这样做时,通常会发生该缩进错误(例如混合制表符/空格,使用太少或太多空格等)。
从您发布的内容来看,缩进看起来不错,但有时很难分辨。以下 Python 2.7.3 会话使用四个空格作为缩进,工作正常:
>>> temp = 62
>>> if temp > 60 < 75:
... print "okay"
... else:
... print "urk"
...
okay
但是当我(愚蠢地)在 之前放置一个空格时else:
,我明白了,类似于你:
>>> temp = 62
>>> if temp > 60 and temp < 75:
... print "okay"
... else:
File "<stdin>", line 3
else:
^
IndentationError: unindent does not match any outer indentation level
你需要加工你的缩进:
if temp > 60 < 75:
print 'just right'
else:
if 是一个条件,下一行(如果 if 语句为 True 则完成)应该缩进,然后else:
应该与 if 语句对齐
Python 使用冒号 (:) 和缩进对语句进行分组,而其他语言使用花括号 ({}) 或圆括号。因此,您需要在 if/else 语句以及 for、while 和 foreach 语句中缩进 Python 语句块。所以你的代码应该是:
if 60 < temp < 75:
print 'just right'
else:
pass # this doesn't execute anything; it's a placeholder
请注意,Python 允许您链接不等式(例如,60 < x < 75
代替x > 60 and x < 75
),尽管许多其他语言不允许。
首先,您的 if 语句需要修复,并且您需要像这样缩进您的行:
if temp > 60 and temp < 75:
print 'just right'
else:
pass # whatever you need to do here