为什么在Python文件中会出现此错误&书信电报;stdin>&引用;,第2行/n新的\u方块。追加(方块[i])/n^缩进错误:需要缩进块吗?

为什么在Python文件中会出现此错误&书信电报;stdin>&引用;,第2行/n新的\u方块。追加(方块[i])/n^缩进错误:需要缩进块吗?,python,python-2.7,Python,Python 2.7,我是python新手,刚刚学习了“While循环”,所以我正在尝试这段代码,其中包括将一个列表的值复制到另一个列表中 >>> squares=['red','red','red','blue','red','red'] >>> new_squares=[]; >>> i=0 >>> while(squares[i]=='red') ... new_squares.append(squares[i]) 现在是错误发生的时候

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

>>> 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
文件“”,第2行
新增方格。追加(方格[i])
^
缩进错误:应为缩进块

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

A
,而
语句应该以
结尾,因此您应该更改

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

然后写下面的代码
新的_方块。在右边的一个缩进级别追加(方块[i])

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