为什么控制台说我的打印“”.join(行)功能有问题?

时间:2013-04-04 00:59:41

标签: python

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)行是有问题的地方,在提交第一项后,它会输入错误(点是对问题不重要的额外代码)

2 个答案:

答案 0 :(得分:1)

该代码没有任何问题,我只是在机器上尝试过。如果您使用的是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

答案 1 :(得分:0)

我认为问题在于您尝试在单个行上使用.join():您可以将它应用于整个数组,它应该可以正常工作。

(你必须改变附加“O”的格式,使其看起来像你想要的那样),