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

Tell us what’s happening:

I have no idea how solve this, it’s really tricky. I’ve had a look at other people posts for this step but still can’t pass. Can someone please help?

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 = []

# User Editable Region

            for square_no, part in enumerate([line[:3], line[3:6], line[6:]], start=1):
                for item in part:
                    '|'.join()
                    str(item)


                    

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Challenge Information:

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

1 Like

Welcome to the forum @minimakl

Now, you would join the elements of the segment (part) with the pipe character (|).
For that, first, use a for loop for item in part to access all elements.
Then, use the join() method on the | character to join the elements of the segment (part).
After that, convert each element to a string using str(item).
You should use the join() method on the | character to join the elements of the segment (part ). add test for “” as well

The instructions are a bit vague on the order of the code.

Start with the join method on |, then use the hint messages to guide you on the rest of the code.

Happy coding

1 Like

The request says:

For that, first, use a for loop for item in part to access all elements

Have you seen this before?

thing for thing in things

List comprehensions uses it, but in this case is a generator.

For the second step:
The string method join() takes a list as argument and joins its members with given string object.

Example from the interpreter

>>> things = ["book", "magazine", "document"]
>>> "||".join(things)
'book||magazine||document'
>>> "|-|".join(thing for thing in things)
'book|-|magazine|-|document'
1 Like

Thank you so much for the reply! I took what you wrote then came up with this code: (I can’t post it because its the answer) and it passed! Thanks so much I really appreciate you for helping!!

Thank you so much for replying!! That is really helpful how you’ve worded it, it makes a lot more sense now. Thanks again, I really appreciate you taking your time to reply to me and help!

1 Like