7) Battleship // 3) Make a list (solved)


#1

I don't understand :disappointed_relieved:
I know that I am definitely doing something wrong but I'm not sure what exactly. I would be grateful to be provided with an explanation, thank you.

It says : Oops, try again. It looks like you do not have 5 rows in your list. <-- ( How would I create 5 rows ?)

Task:

Create a 5 x 5 grid initialized to all 'O's and store it in board.

Use range() to loop 5 times.
Inside the loop, .append() a list containing 5 "O"s to board, just like in the example above.

My code:

board = []
for board in range(len(board)):
    board.append(["O" * 5])[board]
for board in range(len(board)):
    board.append(["O" * 5])[board]
for board in range(len(board)):
    board.append(["O" * 5])[board]
for board in range(len(board)):
    board.append(["O" * 5])[board]
for board in range(len(board)):
    board.append(["O" * 5])[board]

#2

Never mind, I understand now, the correct code is:

board = []

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

#3

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