Why won't my print_board function work?


#1

Okay... I'm stumped here.

I breezed through the entire tutorial and everything worked perfectly.

Now, I am on the extra credit, and I can't get my board to print in the "pretty" fashion using the join function.

I've used a bit of a different approach to build the boards, and made them larger, but generally followed the same principles from the tutorial. But, when I call my print_board function, I get no output at all--nothing.

Any help?

Here's my code:

    board_1 = []
board_2 = []

def build_board(board):
    row = []
    for j in range(10):
        row.append('O') #build your row
    board = [row] * 10 #add each row
    print board
    
def print_board(board):
    for i in range(0, len(board)):
        print " ".join(board[i])
    
build_board(board_1) #build the boards
build_board(board_2)

print 'Board 1'
print_board(board_1) #show our boards
print 'Board 2'
print_board(board_2)

And, here's what I'm getting in the console (note that the printed list is from my debugging code--showing that the lists are populated correctly, but the print that should be happening in the "pretty" format is just...not working, at all.

[['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', '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'], ['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', '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']]
[['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', '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'], ['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', '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']]
Board 1
Board 2
None

#2

Okay, I apologize. I posted too soon.

I now realize that what I was trying to do didn't work. I wrongfully assumed that simply running the function and passing the name of the list would be sufficient to set that list within the function.

Now, I see that I need to return the output and set it equal when I execute the function.

New code:

board_1 = []
board_2 = []

def build_board(board):
    row = []
    for j in range(10):
        row.append('O') #build your row
    board = [row] * 10 #add each row
    return board
    
def print_board(board):
    for i in range(len(board)):
        print " ".join(board[i])
    
board_1 = build_board(board_1) #build the boards
board_2 = build_board(board_2)

print 'Board 1'
print_board(board_1) #show our boards
print 'Board 2'
print_board(board_2)

I do still have a question though: Is this the only way to do this? Could I assign the value of the board_1 variable from within the build_board function?