I'm trying to make a class which creates empty board objects as part of a board game project. Here's what I came up with :
class Board:
board = []
# Initially the board is empty
def __init__(self, size=9):
# If n is the size of the board
# Each line is a list of n colums
# Each column is initially set as a list of n empty squares
for line in range(size):
list = []
for columns in range(size):
list.append("O")
self.board.append(list)
return None
def __repr__(self):
# Lines separator is '\n'
# Columns separator is ' '
repr = ''
for n_line in range(len(self.board)):
for n_column in range(len(self.board[n_line])):
repr += self.board[n_line][n_column] + ' '
repr += '\n'
return repr