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: load_puzzle(), display_puzzle(), get_next(), get_options(),
copy_puzzle(),and solve(). Descriptions of each of these functions are provided below.
load_puzzle()
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 9 lines of text, each
of which contains 9 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 sub-list containing the 9 values on any one line of the file, stored as
integers.
The function should complete the desired task by performing the following steps:
1. Use open() and read() to read in the contents of the file indicated by path as a string.
2. Split the string from the previous step on the newline character, storing the result in a list named lines.
3. Create an empty list named puzzle.
4. 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 token_strings.
b. Create a list named token_ints that contains the values from token_strings, but coerced to
integers. You can do this with a loop or a list comprehension.
c. Append the list token_ints to puzzle.
5. Return puzzle.
display_puzzle()
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:
1. Loop over the elements puzzle. Fir each list in puzzle, perform the following steps:
a. If considering the list at index 0,3, or 6, 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 2,5, or 8, concatenate the string '|' to row.
d. After the inner loop finishes, print row.
2. 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!