# Learn Classes and Objects by Building a Sudoku Solver - Step 59

### Tell us what’s happening:

Hi everyone, I’d really appreciate some help with this step. I am confused as to why my code isn’t passing because I did create a new method called solver within the Board class that takes in self as a parameter. Is there something I’m missing? Thanks.

``````class Board:
def __init__(self, board):
self.board = board

def __str__(self):
upper_lines = f'\n╔═══{"╤═══"*2}{"╦═══"}{"╤═══"*2}{"╦═══"}{"╤═══"*2}╗\n'
middle_lines = f'╟───{"┼───"*2}{"╫───"}{"┼───"*2}{"╫───"}{"┼───"*2}╢\n'
lower_lines = f'╚═══{"╧═══"*2}{"╩═══"}{"╧═══"*2}{"╩═══"}{"╧═══"*2}╝\n'
board_string = upper_lines
for index, line in enumerate(self.board):
row_list = []
for square_no, part in enumerate([line[:3], line[3:6], line[6:]], start=1):
row_square = '|'.join(str(item) for item in part)
row_list.extend(row_square)
if square_no != 3:
row_list.append('║')

row = f'║ {" ".join(row_list)} ║\n'
row_empty = row.replace('0', ' ')
board_string += row_empty

if index < 8:
if index % 3 == 2:
board_string += f'╠═══{"╪═══"*2}{"╬═══"}{"╪═══"*2}{"╬═══"}{"╪═══"*2}╣\n'
else:
board_string += middle_lines
else:
board_string += lower_lines

return board_string

def find_empty_cell(self):
for row, contents in enumerate(self.board):
try:
col = contents.index(0)
return row, col
except ValueError:
pass
return None

def valid_in_row(self, row, num):
return num not in self.board[row]

def valid_in_col(self, col, num):
return all(
self.board[row][col] != num
for row in range(9)
)

def valid_in_square(self, row, col, num):
row_start = (row // 3) * 3
col_start=(col // 3) * 3
for row_no in range(row_start, row_start + 3):
for col_no in range(col_start, col_start + 3):
if self.board[row_no][col_no] == num:
return False
return True

def is_valid(self, empty, num):
row, col = empty
valid_in_row = self.valid_in_row(row, num)
valid_in_col = self.valid_in_col(col, num)
valid_in_square = self.valid_in_square(row, col, num)

# User Editable Region

return all([valid_in_row, valid_in_col, valid_in_square])
def solver(self):

# User Editable Region

Hi everyone, I'd really appreciate some help with this step. I am confused as to why my code isn't passing because I did create a new method called solver within the Board class that takes in self as a parameter. Is there something I'm missing? Thanks.

User Agent is: <code>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36</code>

### Challenge Information:
Learn Classes and Objects by Building a Sudoku Solver - Step 59
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-classes-and-objects-by-building-a-sudoku-solver/step-59``````

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

It looks ok. The spacing is a little strange, in that there’s no space between the previous line. Try to reset the lesson and try it again.

I’ve found you also need to press “Enter” after the line so there is a blank line below. You can also write “pass” in the body which is more correct. Python will give you an error if you have a function with a blank body.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.