Tweak the str printing a bit

This commit is contained in:
Eryn Wells 2017-10-10 09:55:34 -07:00
parent 93a4fecb26
commit 19a9bc9d37

View file

@ -94,9 +94,9 @@ class Sudoku:
def __str__(self): def __str__(self):
field_width = len(str(self.size)) field_width = len(str(self.size))
dim = int(math.sqrt(self.size)) dim = self.dimension
lines = [] lines = []
spacer = '+' + '+'.join(['-' * (field_width * dim) for _ in range(dim)]) + '+' spacer = '{0}{1}{0}'.format('+', '+'.join(['-' * (field_width * dim) for _ in range(dim)]))
for line in range(self.size): for line in range(self.size):
chunks = [] chunks = []
for i in range(dim): for i in range(dim):
@ -107,7 +107,7 @@ class Sudoku:
chunks.append(''.join(fields)) chunks.append(''.join(fields))
if (line % dim) == 0: if (line % dim) == 0:
lines.append(spacer) lines.append(spacer)
lines.append('|' + '|'.join(chunks) + '|') lines.append('{0}{1}{0}'.format('|', '|'.join(chunks)))
lines.append(spacer) lines.append(spacer)
fmt = '\n'.join(lines) fmt = '\n'.join(lines)
str_board = [str(n) if n != 0 else ' ' for n in self._board] str_board = [str(n) if n != 0 else ' ' for n in self._board]