6. Printing Pretty


#1

Have been working on def print_board and keep getting the error: name ‘row’ is not defined, have compared my code to others on the forum and can see no difference.
My code below


for i in range(5):
  board.append(["O"] * 5)

def print_board(board):
    for row in board:
        print" ".join(row)
print_board (board)

#2

Did you create your board variable yet (it’s an empty list)? I don’t see it here.

I tested your code and it works for me.


#3

Yes, line one is
board=[]

I get run window (black background) I get a 5 x 5 table of O’s, but the error message appears from the code academy feedback. Could it be to do with indenting? Since code academy updated, tab no gives me 2 spaces, so I have been manually entering 4 spaces, is this correct?


#4

No, I don’t think that’s the problem. I think we’re supposed to do 2-space indentation.


There are bugs within the Python courses and Codecademy is working on it.


#5

Ok, I will ignore the error message then. I have checked all my indenting is set to 2 spaces for each indent.
Thanks for your help


#6

You’re welcome. Sorry for the inconvenience.


#7

While 2 spaces is fine for Python, the lesson checker may be expecting consistent 4 space indentations.


#8

Hmm okay, I tested it with 2-spaces and it worked. Well, at least I know. Thanks @mtf.


#9

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