Battleship 5/19 whats wrong with my code?


#1

Hey guys,

Here is my code:

board = []
for i in range(0,5):
board.append(['O' * 5])

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

print_board(board)

it prints out correctly as:

OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
None

but I'm still getting:
Oops, try again. It looks like you function didn't print out the correct response!

Any idea why?


#2

Hi @9868john,

Because your code is not formatted, it is difficult for other users to read and debug it. As code is being posted, you can format it by selecting it, and then by clicking the </> button above the editing area. This will enable us to see important details, such as the indentation and underscores.

You have:

print(' '.join(row))

The output is nice, but does not look like what Codecademy wants at this point. It should look like this:

['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']

To get that, change your statement to:

print row

#3

Thanks for the tip @geomaticmashups,

Here is my formatted code, i've changed it to print row but its still not working :frowning: but everything looks right? it seems to print correctly as well.

board = []
    for i in range(0,5): 
        board.append(['O' * 5])

    def print_board(board):
        for row in board:
            print row

    print_board(board)