Battleships exercise 3


#1

Hello!

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

In 3/19 Help me please! Why don’t work?


Range(5)
#2

And this don’t work too:(

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

Results

['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']
['O', 'O', 'O', 'O', 'O']

But "It looks like the rows are not represented as lists."
Please explain why the program does not accept?


#3

Note that you’re printing the board 6 times.


#4

Most likely, there is another mistake.

for i in range(0,5):
  result.append(i)
  print(board)

does not accept too…


#5

Now you’re printing the board 5 times

If you print it 5 times and it looks like a whole board, then you’ve got a fifth of a board, right?

It’s not what’s shown on screen that matters, what matters is what value your board variable refers to

The board should be a list containing other lists. Each inner list represents a row. There should be five inner lists, one for each row, and each inner list should contain 5 elements, one for each column.

If you were to print the whole board 5 times, then you should end up with a total of 5*25=125 elements having been printed

Also, you need to take special care that you aren’t adding the same row five times. You should add five identical rows. (otherwise shooting at one location will look like you shot at five locations because the same row is replicated 5 times)


#6

Thank you very much!


#7

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