Learn Classes and Objects by Building a Sudoku Solver - Step 20

Tell us what’s happening:

Confused on what the question is trying to ask me to do.

Your code so far

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)

                if square_no != 3:

# User Editable Region

            row = f'║ {" ".join(row_list)} ║\n'
            row.replaced(0, ' ') 

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0

Challenge Information:

Learn Classes and Objects by Building a Sudoku Solver - Step 20

You have the right idea but your code is not quite correct.

Firstly, the method is replace not replaced.
It may not be clear but the numbers which fill the grid will be in string (as opposed to integer) form, so you need change the first argument in your replace method to a string.
Finally, that amended code is assigned to the variable row_empty.
All of this can be done with a single line of code.

1 Like

I’m guessing I am going the right way like this?

row = f’║ {" “.join(row_list)} ║\n’
row.replace(” ", " ")

Hi there. When you would pass your input puzzle board, 0 would be used for empty cells.

And afterwards you will save this value to row_empty.

What I meant is that you should turn the 0 into a string in your replace method (i.e. put quote marks around it).
You can declare the variable row_empty at the beginning of the line and its assigned value is the other code which you’ve written (i.e. row.replace etc).

1 Like

Ah, that was the solution. I didn’t think to turn 0 into a string. Much appreciated.

row_empty = row.replace(" ", “0”)

That is back to front. That will replace all spaces with zeroes. You should replace all zeroes with spaces.

oh i got it now, sorry for not getting early on

1 Like


Edit: The answer marked as “solution” isn’t a solution to the original problem, it’s a solution to a later incorrect alteration.

Fixed this. Adding extra characters to satisfy the 20 minimum words requirement.