How to print a board in python? -


i trying program game called triple triad on python, have problem output of board, has every square, each number represents cardinal point,there 9 squares, 3 every line.

| 1 | 1 | 9 |  |2@3|1*6|7*2|  | 4 | 1 | 2 | 

i thought doing list every line , start board numbers every cardinal point, example, "0" if north or that, when have replace numbers of card, know put every cardinal point, suggestions?

thanks in advance

here simple way format looking for:

def format_row(row):     return '|' + '|'.join('{0:^3s}'.format(x) x in row) + '|'  def format_board(board):     # single list 9 elements uncomment following line:     # return '\n\n'.join(format_row(row) row in zip(*[iter(board)]*3))     # 3x3 list:     return '\n\n'.join(format_row(row) row in board) 

example:

>>> print format_board([['1', '1', '9'], ['2@3', '1*6', '7*2'], ['4', '1', '2']]) | 1 | 1 | 9 |  |2@3|1*6|7*2|  | 4 | 1 | 2 | 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -