6. Printing pretty - only it's not!


#1



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...))


#2

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


#3

Duh!

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?


#4

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

myFunction("Hello")

#5

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

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


#6

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