Question: Python 3 Coding: Here is the coded I already have for reference since the page of code I will attach relies on some of the
Python 3 Coding:
Here is the coded I already have for reference since the page of code I will attach relies on some of the portions of code underneath. The picture of the page attached is what I need assistance with. Thank you for any help.
#make an "empty" n by n board. Empty boards are filled with None. Assume n > 0. #Note: you must create a board with n separate rows instead of n shallow copies of one row. def make_empty_board(n): l = [] for i in range(n): l2 = [] for k in range(n): l2.append(None) l.append(l2) return l
#given a location tuple (row, col) determine if those coordinates are valid locations in the puzzle. #You do not need to check if value is valid. Note only non-negative indexes are allowed to use. def is_valid_location(loc, puzzle): dim = len(puzzle) x,y = loc if (x
#determine if the puzzle has any remaining None locations. You do not need to check if the puzzle #is a valid solution. def is_complete(puzzle): for x in range(len(puzzle)): for y in range(len(puzzle)): if puzzle[x][y] == None: return False return True
#given a location as a tuple (row, col), return the value at that location of the given puzzle. #You may assume that the location provided is a valid location. def get_value_at_location(puzzle, loc): x,y = loc return puzzle[x][y]
#given a puzzle, a value, and a location (row, col), try to set the puzzle location to that #value. If the puzzle location is empty, set the value and return True. If the location is already #set, or the location is invalid, do not modify the puzzle and return False. You do not need to #check if value is valid. (HINT: use is_valid_location() to check for valid locations.) def set_location(puzzle, value, loc): x,y = loc if is_valid_location(loc, puzzle): puzzle[x][y] = value return True else: return False

unset location(puzzle, loc): given a puzzle and a location (row, col), try to remove the value at that location (change to None). Return True if the puzzle was successfully changed (the value at that location is removed). Return False if the location is not valid, or there is currently no value at that location. (HINT: use is valid location to check for valid locations.) unset-location ([[11], (0,0)) True puzzle is now [None unset location ([[1], (0,1) False location is invalid unset location ([[None]], (0,0)) False location is already None unset location ([[1,2],[1,11], (1,0)) True puzzle is now [[1,2], [None,111 get size (puzzle): given a puzzle, return its size as an integer. You do not need to check whether the given puzzle is valid get size([[None,None],[None,Nonell) #2x2 puzzle get size([[1,2,3],[2,1,3], [None, None,3]]) #3x3 puzzle get size ([[51]) #1x1 puzzle get valid numbers (size): given a positive size, return a list of the numbers which can be validly placed in a puzzle of that size o get valid numbers (2) [1,2] #2x2 puzzle et valid numbers (3) [1,2,3] #3x3 puzzle get valid numbers (1) [1] #1x1 puzzle contains only valid symbols (puzzle, complete) check if a puzzle contains only valid numbers. If the puzzle is incomplete, also allow None in the puzzle. complete will be a boolean indicating whether or not the puzzle is complete. You do not need to check that the puzzle is valid, only if the numbers used are correct. (HINT: use get valid numbers contains only valid symbols([[1]], True) True contains 1, the only valid valu contains only valid symbols [None] True) False complete puzzle should not contain None contains only valid symbols([[Nonell, False) True puzzle is incomplete so None is ok contains only valid symbols([[1,1],[1,11], True) True puzzle contains only valid values (1s and 2s) has repeat(xs, v): given a list of numbers xs and a number n, check whether xs has repeated values of n. Return True if v occurs more than once in xs; return False otherwise. You may not use .count has repeat ([None], 1) False has repeat 1, 2, 3, 1) False has repeat ([1,2,1], 1) True row index return the row at the specified row index from puzzle as a list. Return get row (puzzle None if the row index is invalid. get row ([[1,None],[2,None]], 0) None] row 0 get row [[1,None Nonell, 1) [2, None row 1 get row([[1,None],[2,None 11, 2) invalid index None
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
