<pre><code>def createOneRow(width):
""" returns one row of zeros of width "width"...
You should use this in your
createBoard(width, height) function """
row = []
for col in range(width):
row += [0]
return row
def createBoard(width,height):
"""creates a list
"""
row = []
for col in range(height):
row += createOneRow(width),
return row
import sys
def printBoard(A):
""" this function prints the 2d list-of-lists
A without spaces (using sys.stdout.write)
"""
for row in A:
for col in row:
sys.stdout.write(str(col))
sys.stdout.write('\n')
</code></pre>
<p>以上是基本函数,然后我被要求执行一个复制函数来跟踪原始<code>A</code>。在</p>
^{pr2}$
<p>然后我试图<code>printBoard(newA)</code>,但错误出现了:</p>
<pre><code>Traceback (most recent call last):
File "<pyshell#37>", line 1, in <module>
printBoard(newA)
File "/Users/amandayin/Downloads/wk7pr2/hw7pr2.py", line 35, in printBoard
for col in row:
TypeError: 'int' object is not utterable
</code></pre>
<p>有人能告诉我为什么这是个错误吗?在</p>