python – join method is not working

Question:

Good! I am creating the battleship game and I encountered a problem creating the board.

Code:

board = []

for x in range(15):
    board.append(["O"] * 15)

def print_board(board):
    for row in board:
        print (" ").join(row)

And when I print to the board it gives me this error:

  print (" ").join(row)
AttributeError: 'NoneType' object has no attribute 'join'

And I don't understand what's wrong… Can anyone help me?

Answer:

Probably the parenthesis sign in the print command should be:

for row in board:
  print(" ".join(row)) # -> aqui!!

After the change, the program prints:

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 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 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
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 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 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
Scroll to Top