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

Tell us what’s happening:

Not understanding what this means call valid_in_row on gameboard. Thats what I did?

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

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

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

gameboard(valid_in_row(0, 8))


# User Editable Region

Your browser information:

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

Challenge Information:

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

So I figured out the first part where you call the method but still not understanding how to print the method?

to print use print

So does that mean without using parenthesis because I’ve tried with and without with gameboard and the valid method inside neither will work.

show what you have tried, please always show your code

gameboard.valid_in_row(0, 8)
print(valid_in_row (0, 8))

and what happens when you have this in your code? do you get an error in the terminal?

Sorry, your code does not pass. You're getting there.

1. Your code raised an error before any tests could run. Please fix it and try again.

that’s not the terminal, check the terminal

My mistake here is whats in the terminal

Traceback (most recent call last):
  File "main.py", line 31, in <module>
NameError: name 'valid_in_row' is not defined

read it and try to understand why do you have that error

I don’t get it it shows it in the code as being a defined method already? def valid_in_row(self, row, num):

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]

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)
gameboard.valid_in_row(0, 8)
print()

yeah, it’s defined in the class, so you can use it like this. you don’t have a valid_in_row to use without an instance of Board


read carefully, you are asked to print the output of what?

Does it have something to do with the third paramater SELF?

what are you asking about?

The note from the instructions " how the method is defined with three parameters, yet it is called with only two arguments because self is automatically passed as the object on which the method is called"

no, it’s really just because you have created the function inside the class, so it exists only inside the class, there is no valid_in_row in the global scope

So then what is asking me to print? The method? Board? gameboard? This step is so vague.

It is asking you to print the result of something, it is mentioned explicitly in the instructions, read carefully and individuate it

So what is explicit about this step? It says pass 0 and 8 then print result? Of what, you just explained the valid_in_row is undefined and I already tried gamebaord, Board, self, and even puzzle with the print() call

Call valid_in_row on gameboard. Pass it 0 and 8 as the arguments and print the result.