Make A List


#1

My code passed, but it doesn't look right. It prints the board in a weird format. How do i fix it?

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


#2

Hello :slight_smile:

It looks ok to me! If you want to print it out in more "natural" way use the for loop and print single row in every iteration:

for i in range(5):
  print board[i]

#3

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

Why does this code print O's in a weird format and """ print board[i] """ prints in a correct format ?


#4

The first code prints out whole board list, which includes five lists of five 'O'. We use a single print statement so it will print everything in single line:

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

Second code prints out every row in the separate line:

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

#6