Battleship Custom Printing, I don't believe I got this right


#1

I don't believe I should have gotten this correct either. My code it below:

board = []
for i in range(5):
' board.append(5 * ["O"])
for z in board:
' for y in z:
'' print y,
' print
def print_board(board):
' for i in range(len(board)):
'' print board[i]

I used ' to help show indents. I get the result of
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

Which is what I wanted, but I don't think my code reflects what my result is though. Can anyone confirm this?


#2

The above would need to be inside the function to be able to run each time.

We can print a row with a single statement:

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

#3

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