What is wrong with my code? 6.printing pretty


Im unsure what is wrong with this code? It gets the correct awnser but it says it is incorrect??

board = []
letter = ["O "]
def create_board():
    for i in range(0,5):
        board.append(" ".join(letter) * 5)
    return board
def print_board(x):
    for i in range (0, len(board)):
        print board[i]



By writing a reference to this in every cell of your list, they will all be the same. Instead of twenty-five unique cells, there are 25 of the one. Change one and you change all. Plus, leave out the space and insert it with the .join() statement.

board = []

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


for i in range(len(board)):
    print " ".join(board(i))


ok thank you very much, that makes sense now :grinning:


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