Back to Freecodecamp

Step 35

curriculum/challenges/english/blocks/learn-classes-and-objects-by-building-a-sudoku-solver/6606cc473675e85017b0c53d.md

latest1.3 KB
Original Source

--description--

The 1 is already present in the first column. So, everything seems to work fine. Now delete your print call.

--hints--

You should not have print(gameboard.valid_in_col(0, 1)) in your code.

js
({ test: () => assert.isFalse(runPython(`_Node(_code).has_call("print(gameboard.valid_in_col(0, 1))")`)) })

--seed--

--seed-contents--

py
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

    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))

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)
--fcc-editable-region--
print(gameboard.valid_in_col(0, 1))
--fcc-editable-region--