繁体   English   中英

为什么我在 Python 文件上收到此错误“<stdin> ”,第 2 行 /n new_squares.append(squares[i]) /n ^ IndentationError: 期望缩进块?</stdin>

[英]Why am I getting this error on Python File “<stdin>”, line 2 /n new_squares.append(squares[i]) /n ^ IndentationError: expected an indented block?

我是 python 的新手,我刚刚了解了“While Loops”所以我正在尝试这段代码,它包括将列表的值复制到另一个列表中

>>> squares=['red','red','red','blue','red','red']
>>> new_squares=[];
>>> i=0
>>> while(squares[i]=='red')
... new_squares.append(squares[i])

现在是发生错误的时候

  File "<stdin>", line 2
    new_squares.append(squares[i])
              ^
IndentationError: expected an indented block

为什么会发生这种情况,我在课程中使用了相同的代码,我只是将值从“橙色”更改为“红色”

while语句应以:结尾,因此您应该更改

while(squares[i]=='red')

while(squares[i]=='red'):

然后在右侧的一级缩进处编写以下代码new_squares.append(squares[i])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM