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

Tell us what’s happening:

what am i doing wrong???

Your code so far


# User Editable Region

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

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

puzzle = [
    [0, 0, 2, 0, 0, 8, 0, 0, 0],
    [0, 0, 0, 0, 0, 3, 7, 6, 2],
    [4, 3, 0, 0, 0, 0, 8, 0, 0],
    [0, 5, 0, 0, 3, 0, 0, 9, 0],
    [0, 4, 0, 0, 0, 0, 0, 2, 6],
    [0, 0, 0, 4, 6, 7, 0, 0, 0],
    [0, 8, 6, 7, 0, 4, 0, 0, 0],
    [0, 0, 0, 5, 1, 9, 0, 0, 8],
    [1, 7, 0, 0, 0, 6, 0, 0, 5]
]

gameboard = Board(puzzle)


# User Editable Region

Your browser information:

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

Challenge Information:

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

Please remember to talk to us about how the instructions or error message is confusing so that its easier for us to help you

1 Like

You should not define the function and put the for loop in the try block.

there isnt an error the message is this You should put the assignment of col inside a try block and create an except clause.

Ok, can you talk to me about how that error message is confusing you?

because ive got this now class Board:

    def __init__(self, board):
        self.board = board

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

puzzle = [
    [0, 0, 2, 0, 0, 8, 0, 0, 0],
    [0, 0, 0, 0, 0, 3, 7, 6, 2],
    [4, 3, 0, 0, 0, 0, 8, 0, 0],
    [0, 5, 0, 0, 3, 0, 0, 9, 0],
    [0, 4, 0, 0, 0, 0, 0, 2, 6],
    [0, 0, 0, 4, 6, 7, 0, 0, 0],
    [0, 8, 6, 7, 0, 4, 0, 0, 0],
    [0, 0, 0, 5, 1, 9, 0, 0, 8],
    [1, 7, 0, 0, 0, 6, 0, 0, 5]
]

gameboard = Board(puzzle)

and ive done what the message says

so this class Board:

    def __init__(self, board):
        self.board = board

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

puzzle = [
    [0, 0, 2, 0, 0, 8, 0, 0, 0],
    [0, 0, 0, 0, 0, 3, 7, 6, 2],
    [4, 3, 0, 0, 0, 0, 8, 0, 0],
    [0, 5, 0, 0, 3, 0, 0, 9, 0],
    [0, 4, 0, 0, 0, 0, 0, 2, 6],
    [0, 0, 0, 4, 6, 7, 0, 0, 0],
    [0, 8, 6, 7, 0, 4, 0, 0, 0],
    [0, 0, 0, 5, 1, 9, 0, 0, 8],
    [1, 7, 0, 0, 0, 6, 0, 0, 5]
]

gameboard = Board(puzzle)

Can you say more than just handing me your code and the error message? I’m trying to understand what specifically in your mind is the sticking point

okay, i put in the code, error message from freecodecamp saying this You should put the assignment of col inside a try block and create an except clause. I now do this as you can see i put the col inside the try block and created an except clause. the message is still there i don’t know whats wrong thats why im handing you my code.

Ok, that’s not really what I asked for. I personally don’t really find it fun to help people by telling them the answer, so I’ll let someone else help you.

Interesting perspective. If you’re only helping people for the fun of it, maybe it’s time to rethink your approach. When someone genuinely has no clue what’s wrong with their code and you ask, “what specifically in your mind is the sticking point,” it’s not always about a specific issue—sometimes, there’s nothing sticking at all, like a non-stick pan. So, if that’s not your idea of fun, perhaps it’s best to step aside and let someone who’s more interested in actually helping take over.

I enjoy helping people for free and donating thousands of dollars of free tutoring time. I don’t enjoy handing people answers when they don’t really engage with discussing the questions. I honestly think that does more harm than help in my experience.

okay then please help me understand what you expected to hear when asking me that question

I’d love to hear how you think your answer exactly matches the instructions and the example given.

Why did you write the except block the way you did, for example?

1 Like

:joy::joy: yeah you were right i know what i did wrong i solved it, it was the valueerror