Battleship 6/13 error


#1

What is wrong with my code? Ive tried several things none work. This is the same code I used for the prior section and it passed the lesson fine. Can someone help, please?

board=[]

def create_board(lst):
 for x in range(0,5):
    lst.append(["o"]*5)

### New Function ###

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


#2

Which part is this exactly and what is the error you're getting?


#3

I don't know where the mistake is. Everything looks fine. I pried calling: Print Print_board(board) and it doesn't work either.

the error I get is :slight_smile:

Oops, try again. It looks like you function didn't print out the correct response!


#5

did you try to put the board list as argument to your create_board() function?


#6

Are you using a lower-case "o"? It's requesting upper-case, maybe that's the problem?


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

for some reason this way worked for me.`


#8

Hi Guillermo,

You had two problems:

  1. You didn't call create_board and then print_board using board as an argument for both the calls.
  2. You had to use upper-case "O" rather than "o".

#9

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

print_board(board)

This function & call outputs the clean 5x5 grid without punctuation, which is what we want.

This Q has a few bugs, I initially passed the page without calling the function (by writing print board) then re-read the instructions. Of course by not calling the function the output was the same list format with square parentheses, commas and quotations. I tried a few different ways, many of which were passed, before realising that I needed to call the function rather than print the initial list.

So I'd say that this section requires a few more checks before passing. Your output looks a bit off, did you call your function?