我有打印出一個網格的戰列艦遊戲(5'行打印5x),並生成一個隨機點供用戶猜測。嘗試打印行號時輸入錯誤
這些都是行:16-20
""" Allows the function to print row by row """
def print_board(board):
for row in board:
for x in enumerate(row):
print('%s " ".join(row)' % (x))
我得到這些錯誤。但是,只是後我改變線20來打印印格旁邊的數量(http://imgur.com/uRyMeLU)圖片有
Traceback (most recent call last): File "C:\Users\Jarrall\pythonPrac\battleship.py", line 23, in <module>
print_board(board) File "C:\Users\Jarrall\pythonPrac\battleship.py", line 20, in print_board
print('%s " ".join(row)' % (x)) TypeError: not all arguments converted during string formatting
我怎麼會拿到這塊代碼打印數量(枚舉排列表的長度?)旁邊的網格?
只是,你的文檔字符串應該在*函數內部,在簽名之後並且縮進到與最外部的'for'相同的級別。 – jpmc26