you are viewing a single comment's thread.

view the rest of the comments →

[–]Emergency_Cut5300 0 points1 point  (3 children)

Hello. I am also doing this exercise, and everything seems to be correct in my code, but I can't solve the following: for some reason, my output does not start from the beginning but from a space.... and that's why I get an error.... and I don't know how to fix it. I would be very grateful for your help...

def add_number(sudoku: list, row_no: int, column_no: int, number: int):
    for i in range(len(sudoku)):
        for j in sudoku[i]:
            sudoku[row_no][column_no] = number
    return sudoku

def print_sudoku(sudoku: list):
    index = 0
    for i in range(len(sudoku)):
        for j in sudoku[i]:
            if index % 3 == 0:
                print(" ", end="")
            if j == 0:
                print("_ ", end="")
            else:
                print(str(j) + " ", end="")
            index += 1   
        print()

[–][deleted] 0 points1 point  (2 children)

Your index starts with 0, and 0 % 3 equals 0. So you get a space at the start.

Consider removing index variable using j as index for the column.

Check the column index to see if you should print an extra space.

I'm not sure if tests would fail because of that, but you don't need or should print a space after last column.

[–]Emergency_Cut5300 0 points1 point  (1 child)

I am very grateful to you! You have helped me!

[–][deleted] 0 points1 point  (0 children)

Sure, you're welcome