I am trying to write a Sudoku game with user input. So the user can choose what row/column it wants to and what number. I have to import it from a text file and have made a save and load function.
I have tried starting with what I know, but I don't know how to proceed, ex. how to make the board correspond with the user input.
sudoku_brett.txt
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 |+-------+-------+-------+
main code
import save_load
import info
import sudoku_brettprint("Velkommen til sudoku, dette er brettet ditt" readFromFile('sudoku_brett.txt')) #giving them an importet boardprint("Vil du gjøre endringer på brettet?") #asking what changes the user wants to makecol = int(input('Hvilken kolonne vil du endre? ')) #changing column
row = int(input('Hvilken rad vil du endre? ')) #changing row
nytt_tall = int(input('Hva skal det nye tallet være? ')) #asking what number the user would likebrett[row - 1][col - 1] = nytt_tallprint('Ditt nye brett:\n') #printing out the board, with the new input numberbruker.print_board(sudoku_brett)
info.py
def check_input(user_input):if user_input.isdigit():if 1 <= int(user_input) <= 9:return Trueprint ("Det kan kun være tall mellom 1-9. Prøv igjen") #telling it can only be number from 1-9return Falsedef print_board(board):for row in board:print(row)def generate_empty_board():return [[[[0 for i in range(3)] for i in range(3)] for i in range(3)] for i in range(3)]print_board(generate_empty_board())
save_load.py
def readFromFile(filename):f = open(filename,'r')innhold = f.read()print(innhold)f.close()def save(filename, board):f = open(filename, 'sudoku_brett')pickle.dump(board, f)f.close()print("Brett lagret") #saveddef load(filename):f = open(filename, 'sudoku_brett')board = sudoku_brett(f)f.close()print("Brett lastet") #loadedreturn board