Custom Print


#1



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


My code looks like it is printing a board that is five by five but it is printing this board five times instead of one time.


board = []

for i in range(0,6):
    board.append(['O'] * 5)

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


#2

board contains the board, you loop should print each row


#3

I changed board to row in the print command and obtained the correct answer. I didn't define anywhere what row is however so I am wondering how this worked.


#4

row is your iterator, you define it in your for loop

then python will assign each item in the board list to row (in order, obviously)


#5

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