Back to Freecodecamp

Step 20

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

latest1.0 KB
Original Source

--description--

Outside the for loop, return None. This handles the case in which no empty cell is found, indicating that the sudoku board is completely filled.

--hints--

You should return None after the for loop.

js
({ test: () => assert(runPython(`_Node(_code).find_class("Board").find_function("find_empty_cell").has_return("None")`)) })

--seed--

--seed-contents--

py
class Board:
    def __init__(self, board):
        self.board = board
--fcc-editable-region--
    def find_empty_cell(self):
        for row, contents in enumerate(self.board):
            try:
                col = contents.index(0)
                return row, col
            except ValueError:
                pass
--fcc-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)