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

Tell us what’s happening:

Let’s try this again (last post failed to post).

The instructions say “Inside the find_empty_cell method, create a for loop and use the enumerate() function to iterate over each row in the sudoku board.
Use row for the index of the current row and contents for the elements of the current row.”

I’ve tried row, contents and index for the positions between for and enumerate. I of course only used two at a time.
I’m at a loss for what else to try.
Please, help!

Very thankful for any advice!

Your code so far

class Board:
    def __init__(self, board):
        self.board = board

    def __str__(self):
        upper_lines = f'\n╔═══{"╤═══"*2}{"╦═══"}{"╤═══"*2}{"╦═══"}{"╤═══"*2}╗\n'
        middle_lines = f'╟───{"┼───"*2}{"╫───"}{"┼───"*2}{"╫───"}{"┼───"*2}╢\n'
        lower_lines = f'╚═══{"╧═══"*2}{"╩═══"}{"╧═══"*2}{"╩═══"}{"╧═══"*2}╝\n'
        board_string = upper_lines
        for index, line in enumerate(self.board):
            row_list = []
            for square_no, part in enumerate([line[:3], line[3:6], line[6:]], start=1):
                row_square = '|'.join(str(item) for item in part)
                if square_no != 3:

            row = f'║ {" ".join(row_list)} ║\n'
            row_empty = row.replace('0', ' ')
            board_string += row_empty

            if index < 8:
                if index % 3 == 2:
                    board_string += f'╠═══{"╪═══"*2}{"╬═══"}{"╪═══"*2}{"╬═══"}{"╪═══"*2}╣\n'
                    board_string += middle_lines
                board_string += lower_lines

# User Editable Region

    def find_empty_cell(self):
        for row, contents enumerate(self.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/ Safari/537.36 Edg/

Challenge Information:

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

You have a syntax error. How do you iterate over an iterable?

I see! Thank you.
Should it be for contents in row? Because I tried that too and that didn’t work either.
I feel so dumb right now.

You are missing a single keyword. row and contents are fine.

I feel like it should be ‘and’ or ‘or’ or ‘in’, but none of them work for me.
Should it be in before enumerate or not?

A for loop is made of:

  • for keyword :white_check_mark:
  • loop variable(s) (in your case row, contents) :white_check_mark:
  • in keyword (MISSING) :x:
  • iterable (in your case enumerate(self.board)) :white_check_mark:

Ohhhhhh how stupid I am.
Thank you so much!
I was soo sure I had already tried that!

1 Like