I have pasted only parts of the code that I find difficult, otherwise it's an ordinary 9x9 soduko board. It's a nested list
board = [
[0,0,6,9,0,5,0,1,0],
[9,7,0,0,1,2,3,0,5],
[0,2,0,0,0,4,8,6,0],
[5,0,3,8,0,0,0,2,0],
[0,0,0,0,0,0,0,0,0],
[0,8,0,0,0,1,9,0,7],
[0,5,4,1,0,0,0,7,0],
[2,0,7,4,5,0,0,9,3],
[0,6,0,7,0,3,1,0,0]
]
def formatted_board():
print(f'{board[0][0:3]} \n {board[1][0:3]} \n {board[2][0:3]}')
print(board[3][0:3],board[4][0:3],board[5][0:3])
print(board[6][0:3],board[7][0:3],board[8][0:3])
print(board[0][3:6],board[1][1:6],board[2][1:6])
print(board[3][3:6],board[4][1:6],board[5][1:6])
print(board[6][3:6],board[7][1:6],board[8][1:6])
print(board[0][6:9],board[1][6:9],board[2][6:9])
print(board[3][6:9],board[4][6:9],board[5][6:9])
print(board[6][6:9],board[7][6:9],board[8][6:9])
def choose_cell():
row = int(input("choose row:"))
column = int(input("choose column:"))
choose_num = int(input("choose a num between 1 og 9:"))
if 0< choose_num <=9:
board[row][column] = choose_num
formatted_board()
else:
print("illegal num try again")
choose_cell()
formatted_board()
goes into choose_cell()
. The first line in formatted_board()
prints okay, but I want to print it in the below format every time someone inserts a code:
0 1 2 3 4 5 6 7 8
+-------+-------+-------+
0 | 0 0 6 | 9 0 5 | 0 1 0 |
1 | 9 7 0 | 0 1 2 | 3 0 5 |
2 | 0 2 0 | 0 0 4 | 8 6 0 |
+-------+-------+-------+
3 | 5 0 3 | 8 0 0 | 0 2 0 |
4 | 0 0 0 | 0 0 0 | 0 0 0 |
5 | 0 8 0 | 0 0 1 | 9 0 7 |
+-------+-------+-------+
6 | 0 5 4 | 1 0 0 | 0 7 0 |
7 | 2 0 7 | 4 5 0 | 0 9 3 |
8 | 0 6 0 | 7 0 3 | 1 0 0 |
+-------+-------+-------+