![]() The find_empty() function returns the cell position in tuple format, for example, (0, 2).In a new function called solve(), use the find function to find the first empty space on the board: def solve (board):.In this case, do not return anything: return None If the script reaches the end of the function, that means the script couldn't find any cells with the value of 0.If the value of the current cell is 0, return the current position of the empty cell: if board = 0:.In a new function called find_empty(), loop through each row and column on the board: def find_empty (board):.These determine which spaces needed solving. You can traverse through the lists to find the spaces that consist of 0s. How to Identify the Empty Spaces to Solve View the puzzle printed onto the screen: python sudoku.py Use the python command to run your Sudoku script. ![]() In a command line, navigate to the folder where you stored your python script, for example: cd Desktop.Call the function to print the board: print_board(board).If the column is the last column for that particular row, add a break line, so that the following row appears on a new line: if col = 8: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |