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

Tell us what’s happening:

Not quite understanding how to pass the arguments and print the result?

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]

    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)

# User Editable Region

gameboard.valid_in_col (0, 7)
print(Board)

# 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 33

hi there you are right in terms of printing yes, well done. however what is the code asking you to do well it says this

Call valid_in_col on gameboard . Pass it 0 and 7 as the arguments to see if the number 7 is allowed in the first column of the board and print the result.

in the brackets/parthensis you call valid_in_colongameboard` and as the arguments you put 0 and 7 now if you dont know what argument and to call something on means google it put in “arguments in python” and to call something on means to combine calling a method and calling a function together however the function is the one with the brackets so like this

class.function(arguments)

1 Like

So what I don’t get is when the instruction says “Call valid_in_col on gameboard” are they saying use parenthesis here or just use the word to start the code? I know an argument is surrounded by parenthesis but why the brackets and where do they go?

calling a function means using the parentheses, calling func means doing func(), and if the function requires arguments those go between the parentheses. This is also true for methods that have to be called on something obj.func()

I attempted this but I don’t think this is what you mean cause it still not working?

gameboard.valid_in_col(self, col, num(0,7))
print(Board)

Hi @Coffeezy

Here is the error message in the console.

image

Try removing self

Happy coding

Now it says col not defined?

Remove that as well.

Then I have num and it says not defined and then all I have left is the 0,7?

This is the message I get now.

You should print the result of calling valid_in_col(0, 7) on gameboard.

… and print the result.

So all on one line.

What needs to be all on one line the code and print statement? Why would this be? Nowhere else have I seen this?

For this challenge print the result, so the function call needs to go in a print call.

Print(gameboard.valid_in_col(0,7))

image

Try lower case for the first letter.

Thanks didn’t notice that, thought it was already, works now. :+1:

1 Like