Battleships - need help


#1

board = []
for i in range(5):
    board.append(["O"] * 5)
def print_board(board):
    for ic in board:
        print iс
print_board(board)

Running and have this message - Something went wrong :( 
Click Close to try again or refresh the page.

What i'm doing wrong? In Visual Studio Code this code is working!

In result window - Traceback (most recent call last):
  File "python/cli_runner.py", line 152, in <module>


#2

you are not using .join() to display the board nicely, use join, the exercise wants you to use join.


#3

Thanks - print (''.join(ic)) and i have no this error. But the code still not working - Oops, try again. It looks like you function didn't print out the correct response! Task - Inside the function, write a for loop to iterates through each row in board and print it to the screen. Code - def print_board(board):
for i in board:
for j in i:
print(j)
dosn't work. Can you help?


#4

@ajaxpro88817

If I remember this lesson correctly, I believe you can remove for j in i: and just have the board printed out 10 times. (I believe it is 10, correct me if I am incorrect.)

Your code might look like this:

for x in range(0,10):
    print(board)

This should print the board out 10 times on seperate lines. Once you get into which board piece to change, your kind of code may be useful. Hope this helped.


#5

Wow! It's work! Thank are lot! The right code:

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

I spent two days and i did it, with your help!)))


#6

Happy to help. Good luck learning python!