6. Printing pretty - only it's not!


Either that or it's the previous exercise...

Lesson says I've completed it and off I go to the next one, but I think my code's incorrect somewhere. Surely the join code should erase all the commas and quotation marks? So why is it when I print board I've got a run of five lists with commas and quotations? And It's not even in a nice grid. I've looked around, and I'm sure my code's correct, since it's like others' codes. Can anyone see why?

board = []
for i in range(0, 5):
    board.append(["O"] * 5)
def print_board(board):
    for row in board:
        print " ".join(row)
        print "---".join(board)
        print row

print board

((Just ignore the extra stuff on the bottom - I was trying to see what the .join should do...))


You've written a nice function called print_board() but you haven't called it anywhere :wink:



Do you know... I've been stuck on that since yesterday!!!

OK ... maybe that didn't work either ... I call the function right? Not the board?


Don't forget that when you define a function that has an argument, you have to provide one when you call it:

def myFunction(x):
    print x



Oh yes ... of course. I got a bit confused I think!

Thank you - I now have 5 neat rows and 5 neat columns!! :smile:


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