-5

so I am trying to make tictactoe and i'm having trouble with the board. when I make 3 list of the 1-9 spots they print out as a whole list including the brackets and commas, for example ex = [1, 2] and it would print that full thing. I've never had this problem before. Can anyone help and is it because im using an Online IDE because of chromebook? Thanks :)

board1 = ["|1|", "2|", "3|"]
board2 = ["|4|", "5|", "6|"]
board3 = ["|7|", "8|", "9|"]
print(board1)
print(board2)
print(board3)

#Output
'|1|', '2|', '3|']
['|4|', '5|', '6|']
['|7|', '8|', '9|'] 
xStrqfe
  • 81
  • 2
  • 8
  • 4
    That's *always* how a list is printed... so no, it's not because it's an online ide. – juanpa.arrivillaga May 05 '17 at 17:37
  • 4
    Is the missing `[` under `#Output` a typo? – Bryan Oakley May 05 '17 at 17:38
  • _" I've never had this problem before."_ That's interesting. Can you provide an example of code you're written where printing a list _doesn't_ display brackets or commas? (note that `for item in mylist: print(item)` doesn't count as printing a list) – Kevin May 05 '17 at 17:38
  • 1
    Printing a list will **always** do that. You should print each item separately or better, use `.join()`. – Juan T May 05 '17 at 17:38
  • I think the issue is the missing start bracket. Do you print something before that? If an errant control code got in there, it may swallow the bracket. – tdelaney May 05 '17 at 17:45
  • Assuming this is the full program, It may well be due to the online IDE. Does the IDE try to color the output? – tdelaney May 05 '17 at 17:51
  • I'm confused. Can you clarify whether the problem is with that first bracket not printing? – tdelaney May 05 '17 at 18:38

2 Answers2

1

Printing a list will always show the commas and brackets.

I think you might be looking for the following:

print(''.join(board1))
print(''.join(board2))
print(''.join(board3))

That will give you the following:

|1|2|3|
|4|5|6|
|7|8|9|
Eric Bulloch
  • 827
  • 6
  • 10
0

I would use:

board = [['1','2','3'],
         ['4','5','6'],
         ['7','8','9']]

for x in board: print('|%s|'%'|'.join(x))

Returning

|1|2|3|
|4|5|6|
|7|8|9|
Juan T
  • 1,219
  • 1
  • 10
  • 21