Back to Freecodecamp

Step 11

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

latest1.2 KB
Original Source

--description--

An attribute is a variable associated with an object, which is used to store data as regular variables.

Inside the __init__ method, assign the board parameter (which is passed when creating an instance of the Board class) to an instance attribute board using self.board.

self.board refers to the board attribute of the instance of the class. It's a variable that belongs to the object created from the Board class.

--hints--

You should delete pass and assign the board parameter to self.board inside the __init__ method.

js
({ test: () => assert(runPython(`_Node(_code).find_class("Board").find_function("__init__").find_body().is_equivalent("self.board = board")`)) })

--seed--

--seed-contents--

py
--fcc-editable-region--
class Board:
    def __init__(self, board):
        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)
--fcc-editable-region--