Battleship! Python


#1

Hey everyone:

I completed most of the courses for Python already, and those which I have not, I decided to go through and finish up. Upon reaching the "Battleship!" lesson, I found one exercise that either I do not understand correctly, or has a bug. The exercise can be found here. My code is as follows:

board = []

for x in range(0,5):
    board.append("O")'

I did not print out the board, but I have tried that before, and it was not the problem. Please let me know as soon as possible. Thanks. :snake:


#2

this will only append one O to each row, not creating the 5 columns. Take a look at the hint of the exercise:

print ["O"] * 5

well hint, i mean the information section


#3

I tried that. Notice that it's in a for loop that does it five times. So it becomes a list of 5 "O"s.


#4

yes, but just 5 rows with each one "O". While you should have 5 rows with 5 "O"'s. You need a 5x5 board.


#5
board = []

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

New code, prints the following:

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

Error thrown:
It looks like you do not have 5 rows in your list.


#6

you want to append this:

board.append(["O"]*5)

to each row:

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

#7

@stetim94 I understand. Just misunderstood. Thanks.