How can I append a list of “O”s to the board?


#1

Question

How can I append a list of “O”s to the board?

Answer

If you’re getting an error message that says something along the lines of Oops, try again! It looks like the rows are not represented as lists., it’s likely because you’ve tried to .append() the character "O" by itself, not as a list.
In the example we see that print ["O"] * 5 results in a single list containing 5 "O"s. This is exactly what we want to be .append()ing to our board inside of the for loop.
If we forget to put brackets around the "O", it ends up just adding 5 strings with 5 "O"s each, like this:
['OOOOO', 'OOOOO', 'OOOOO', 'OOOOO', 'OOOOO']


FAQ: Learn Python - Battleship - Make a List