6. Printing pretty but doesn't pass


#1

def grid_creator(item, width, height):
board = []
for _ in range(height):
board.append([item]*width)
return board

def print_board(board):
for row in board:
print " ".join(row)

grid = grid_creator("O", 5, 5)
print_board(grid)

--------appeared in the console ---------

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
None

------------Question-----------------

I think the code and the result look pretty, but system returned
"Oops, try again. Don't modify or delete board!"
Please kindly help! Thank you :smiley:


#2

The lesson checker cannot see your board list. It needs to be in global scope. You have it hidden inside a function.

Will continue to review and test your code, but I would suggest also that you stay with the instructions to complete this project. Once you pass the course, then come back and use the IDE as a sandbox to test your ideas.

Try this and see what happens (not tested)...

board = grid_creator("O", 5, 5)
print_board(board)

#3

mtf! it works! thank you so much for the lightspeed reply !


#4

Passed lesson 7 with a refactoring of your idea:

def set_board(char,cols,rows):
    return [ [ str(char) ] * cols for i in range(rows) ]

board = set_board('O',5,5)

Still playing and testing.