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

Tell us what’s happening:

It is asking me to replace pass, but I need it in order for the code to work, otherwise it will throw up an error.
I have created the expression as it has asked, but no luck.

Your code so far

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)
                return row, col
            except ValueError:
                pass
        return None

# User Editable Region


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


# User Editable Region

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)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

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

:balloon:Hello @cjh78 ! Welcome to the forum!

Ok, so the step states to replace the pass with an expression. Granted an if statement is what one might reach for in this case, especially given the way the challenge is worded.

But, for now at least you want just the expression that checks whether the num in contained in the row. Just the ‘condition’ part of the if statement…

Does this help?
Keep up the good progress!

Happy Coding! :slightly_smiling_face:

If you replace the pass with code, then you no longer need the pass.

2 Likes

Wow, Thank you! It worked. Still a beginner and learning :slight_smile: I appreciate the clarity you provided.

1 Like