擅长:python、mysql、java
<p>首先,请避免使用内置函数的名称作为变量名(在您的情况下,<code>list</code>;我已经将其更改为<code>l</code>)。除此之外,如您所述放置一个标签仅仅是指您拥有的最外层循环的迭代。以下代码应按预期运行:</p>
<pre><code>x = int(input("Enter the desired height. "))
l = [1]
for i in range(x):
# Modified v
print("Row", i + 1, l)
newlist = []
newlist.append(l[0])
for i in range(len(l) - 1):
newlist.append(l[i] + l[i+1])
newlist.append(l[-1])
l = newlist
</code></pre>
<p>下面是一个运行示例:</p>
<pre><code>Enter the desired height. 4
Row 1 [1]
Row 2 [1, 1]
Row 3 [1, 2, 1]
Row 4 [1, 3, 3, 1]
</code></pre>
<p>希望这有帮助!</p>