19/5 Custom Print (need explanation)


#1

board = []
for i in range(5):
__board.append(['O'] * 5)
def print_board(board):
__for row in board:
____ print row
print print_board(board)

why does
def print_board(board):
__for row in board:
____ print row

prints everything in new line?


#2

Every time you print after a different 'print' it will go down to the next line:

print "Hello"
print "World!"

if this code is run, on the console you will see:

Hello
World!

In the for loop you have created (for row in board...), the 'print' command is repeated several times, here is part of the loop broken down:

hope this helps. sorry if it doesn't


#3

Thank you!
.........


#4

Did it help you?????


#5

I got it now :smiley:
thx man
(it definitely help my out)


#6

You're welcome :grinning:


#7
board = []

for x in range(0, 5):
    x = 'O'
    board.append([x]*5)
    
def print_board(board):
    for O in range(0, len(board)):
        print board[O]

print_board(board)

This one works for me. Try this this out.