# Make a list

#1

``````board = []
for lst in range(0,5,1):
board.append('O')
for lst in range(0,5):
print board``````

Below is the error that occurs
Oops, try again. It looks like the rows are not represented as lists.

This is the result of my code, I'm unsure why it doesn't work:
['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']

``Replace this line with your code.``

#2

you should have a multiply dimensional list when you do `print board`:

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

look what you have:

``````board = []
for lst in range(0,5,1):
board.append('O')
print board``````

which will output:

``['O', 'O', 'O', 'O', 'O']``

you will need to append 5 O's for each iteration of the loop, see the information of the exercise for some help:

``print ["O"] * 5``

#3

Your list has only one row.

``````>>> print board
['O', 'O', 'O', 'O', 'O']``````

To create a board with 5 rows and 5 columns,

``````for i in range(5):           # 0 is the default start, and 1 is the default stride
board.append(['O'] * 5)  # one row list, appended 5 times``````

``````>>> print board
[['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']]
>>>``````

Now we have five rows, and five columns. The next lesson will cover `pretty printing` of the five lists.

#6

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