Python IDLE上的缩进错误

Python IDLE上的缩进错误,python,indentation,Python,Indentation,我只是在学习python的基础知识,一直在使用IDLE,因为我发现它可以方便地实时测试脚本 虽然我可以将此脚本作为文件运行,但我不能在IDLE!中包含最后一条print语句!。我试过缩进,4个空格,没有缩进。请解释我做错了什么 while True: print ('Who are you?') name = input() if name != 'Joe': continue print('Hello, Joe. What is the pass

我只是在学习python的基础知识,一直在使用IDLE,因为我发现它可以方便地实时测试脚本

虽然我可以将此脚本作为文件运行,但我不能在IDLE!中包含最后一条print语句!。我试过缩进,4个空格,没有缩进。请解释我做错了什么

while True:
    print ('Who are you?')
    name = input()
    if name != 'Joe':
        continue
    print('Hello, Joe. What is the password? (It is a fish.)')
    password = input()
    if password == 'swordfish':
        break
print('value')
SyntaxError: invalid syntax

一次可以键入一条语句。
while
循环被认为与循环本身是一个循环,因为循环是一个代码块,所以它中的所有内容都是正常的


然而,末尾的
打印
是一个新命令。您必须先运行
while
循环,然后在解释器中键入
print

您可以一次键入一条语句。
while
循环被认为与循环本身是一个循环,因为循环是一个代码块,所以它中的所有内容都是正常的


然而,末尾的
打印
是一个新命令。您必须先运行
while
循环,然后在解释器中键入
print

一次不能将多条语句粘贴到IDLE中。这个问题与缩进无关。
while
循环构成一个复合语句和最后的
print
另一个语句

当您尝试立即粘贴到空闲中时,也会出现以下问题:

print('A')
print('B')

这个问题的事实更清楚地表明,问题不在于缩进。

一次不能将多条语句粘贴到IDLE中。这个问题与缩进无关。
while
循环构成一个复合语句和最后的
print
另一个语句

当您尝试立即粘贴到空闲中时,也会出现以下问题:

print('A')
print('B')

这有一个问题的事实更清楚地表明,问题不在于缩进。

如果第10行有一个缩进错误,那么只需添加一个espace即可

while True:
    print ('Who are you?')
    name = input()
    if name != 'Joe':
        continue
    print('Hello, Joe. What is the password? (It is a fish.)')
    password = input()
    if password == 'swordfish':
        break
    print('value')

第10行有一个定位错误,那么只需添加一个espace即可

while True:
    print ('Who are you?')
    name = input()
    if name != 'Joe':
        continue
    print('Hello, Joe. What is the password? (It is a fish.)')
    password = input()
    if password == 'swordfish':
        break
    print('value')

正如其他人善意地指出的那样,pythonidle一次只允许执行一个代码块。在本例中,while循环是一个“块”。最后一个print语句在这个块之外,因此无法执行。

正如其他人善意地指出的那样,python IDLE一次只允许执行一个代码块。在本例中,while循环是一个“块”。最后一个print语句不在此块中,因此无法执行。

我认为是这样的。谢谢大家的帮助,我想是这样的。谢谢大家的帮助。