Question: Instructions for the Script File Define functions with the following names: load _ puzzle ( ) , display _ puzzle ( ) , get _
Instructions for the Script File
Define functions with the following names: loadpuzzle displaypuzzle getnext getoptions
copypuzzleand solve Descriptions of each of these functions are provided below.
loadpuzzle
This function should accept a single parameter named path. This parameter is expected to be a string indicating the
path to a text file containing the initial state of a sudoku puzzle. The file will be expected to contain lines of text, each
of which contains numbers separated by spaces. The function should open the file and process the lines within. The
function should return a list of lists, with each sublist containing the values on any one line of the file, stored as
integers.
The function should complete the desired task by performing the following steps:
Use open and read to read in the contents of the file indicated by path as a string.
Split the string from the previous step on the newline character, storing the result in a list named lines.
Create an empty list named puzzle.
Loop over the elements of lines. Perform the following steps for each string in lines:
a Split the string on spaces, storing the result in a list named tokenstrings.
b Create a list named tokenints that contains the values from tokenstrings, but coerced to
integers. You can do this with a loop or a list comprehension.
c Append the list tokenints to puzzle.
Return puzzle.
displaypuzzle
This function should accept a single parameter named puzzle. This parameter is expected to be a list of lists
representing a puzzle state. The function should print the puzzle state using the format displayed above on the right.
The function should complete the desired task by performing the following steps:
Loop over the elements puzzle. Fir each list in puzzle, perform the following steps:
a If considering the list at index or print the following string:
b Create a string named row that is initially set equal to We will concatenate values to this string to
build up the desired output for the current row.
c Loop over the elements of the current list, which will be int. For each int value, do the following:
i If the current value is zero, concatenate the string to row.
ii Otherwise, coerce the value to a string, and concatenate that and a space to row.
iii. If considering the element at index or concatenate the string to row.
d After the inner loop finishes, print row.
After the outer loop finishes, print the bottom border of the puzzle:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
