[英]why is the console saying something is wrong with my print “ ”.join(row) function?
import random
print "Welcome to my mastermind game. instead of colors, \
we will be using numbers, one through six \
(red is left, white is right)"
board = []
for x in range(0, 10):
board.append(["O"]*4)
def mastermind_board(board):
for row in board:
print " ".join(row)
...
mastermind_board(board)
turn + 1
print " ".join(row)
行是有問題的地方,在提交第一項后,它會出現錯誤(點是對問題不重要的多余代碼)
該代碼沒有錯,我只是在機器上嘗試過。 如果您使用的是Python 3.3,則需要為打印功能添加括號。 嘗試:
print(" ".join(row))
這是我得到的輸出:
O O O O
O O O O
O O O O
O O O O
O O O O
O O O O
O O O O
O O O O
O O O O
O O O O
我認為問題在於您試圖在單個行上使用.join():您可以將其應用於整個數組,並且應該可以正常工作。
(不過,您必須更改附加的“ O”的格式,以使其看起來像您想要的樣子)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.