Make a list


#1

Error message is saying - Looks like you don’t have 5 rows in your list

But I do get the following output of my code:

[[‘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 they are not in rows.

Battleships - Make a list

Here is my code:



board = []


def one_row():
  return ["O"] * 5
  
def full_board(lists):
  board = []
  for i in range(0,5):
    board.append(lists)
  return board


print full_board(one_row())


I am not seeing what I am doing wrong here. Any pointers are really appreciated. Thank you.


#2

Suggest you to do the following for that excercise in order to work:
board=[[‘O’,‘O’,‘O’,‘O’,‘O’]]
for x in range(0,4):
board.append([‘O’]*5)

print board


#3

Thank you for giving me a solution. I guess creating functions was unnecessary.
But what I don’t get is - How do you get all your “O”-rows in a row, and I don’t?. We still get the same result, but displayed differently.


#4

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