Battleship! Printing Pretty


#1

I know that I'm not doing this right because my board still does not look correct.

board = []
for i in range(0,5):
    board.append(["O"] * 5)
def print_board(board):
    for row in board:
        print row.join(row)

print board

any help or insight/clue is greatly appreciated.


#2

nvm I just toyed with the window and it looks ok, but still how do I know for sure?


#3

It should basically look like this in your output window:
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

Your code is right, apart from this line:

print row.join(row)

Using the join function, your basically telling it to join what's in the brackets using the thing your running the function on, for example a space. The line should look like this:

print " ".join(row)

The line tells the program to join the row values using a space in between them.


#4

thank you I changed it. Makes sense given the character or lack thereof is what we will be .joining

print " ".join(row)

looks good now :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.