3. Make a List help


#1



https://www.codecademy.com/courses/python-beginner-en-4XuFm/0/3?curriculum_id=4f89dab3d788890003000096#


I just don't understand. I followed the instructions, did the hint, looked at other peoples code and still it doesn't work. Can someone explain to me what I'm missing?


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

OUTPUT:
'''[['OOOOO'], ['OOOOO'], ['OOOOO'], ['OOOOO'], 
['OOOOO']]
None'''
ERROR:
Oops, try again. It looks like not all of your rows have 5 columns.


#2

Try getting rid of the spaces before and after the " O ", change it to "O"


#3

Inside the loop, .append() a list containing 5 "O"s to board, just like in the example above.

There is a difference between "O" and " O ", right?


And this code:

["O" * 5]

will create a string - "OOOOO" and you are supposed to append a list, so you have to change this to:

["O"] * 5

#4

You need to print your board list index by index like so:

board = []

def grid(list):
    for numbers in range(5):
        board.append(["O"] *5)
    return board

def print_board(board):
    for row in board:
        print row


print_board(grid(board))

You are printing board normally which will just display the contents of the list in a wrapped format


#5

You are printing board normally which will just display the contents of the list in a wrapped format

And this is exactly what he is supposed to do in this exercise :slight_smile:


#6

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