Reputation: 183
I'm trying to output a tic-tac-toe board and having a difficult time. I'm on Python 3.3.5. I tried at first to do it all as one, but had to break it down to isolate the error. Here's what I have so far:
board1="-"*8
null= " "
board2=(("|"+null)*4)
board3=((board1,'/n',board2,'/n')*3)
printing the board1 and board 2 parts works perfectly. It's any way that I try that encompasses them both in one variable (which I need to for the assignment I'm working on) that doesn't work at all, entirely due to the new line operator not working for me. I've tried without quotes, with single quotes, with double quotes. How am I supposed to use this thing?
Upvotes: 0
Views: 234
Reputation: 6075
Try using \n
instead of /n
. It appears you are using the incorrect slash.
I'm not sure whether you are purposely creating tuples or not, but if you wanted to print the board it could be as simple as the following:
board=(("-"*8,("| ")*4))*3
for line in board:
print line
This iterates through each line in the variable board
, printing the line then moving to a new line. Note that no newline character is required at all. You could even simplify this further if you wanted.
This outputs:
--------
| | | |
--------
| | | |
--------
| | | |
which is what your code for board3
is currently attempting to do.
Upvotes: 3
Reputation: 21562
I think its \n not /n . also, i think your board3 will contain 3 tuples, not the same string repeated three times. Not sure if that's what you want or not. If not replace the commas with +
Upvotes: 1