Question: Python 3 Coding: Here is the code I have finished for the other half of the project. This is relevant because some of the functions

Python 3 Coding:

Here is the code I have finished for the other half of the project. This is relevant because some of the functions build upon other defined functions:

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

def is_valid_location(loc, puzzle): dim = len(puzzle) x,y = loc if (x

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

def get_value_at_location(puzzle, loc): x,y = loc return puzzle[x][y]

def set_location(puzzle, value, loc):

x,y = loc if is_valid_location(loc, puzzle) == True: puzzle[x][y] = value return True else: return False

def unset_location(puzzle, loc): if is_valid_location(loc, puzzle) == False: return False x,y = loc row = puzzle[x] element = row[y] if element == None: return False else: row[y] = None return True

def get_size(puzzle): count = 0 for row in puzzle: count += 1 return count

def get_valid_numbers(size): validList = [] for i in range(1, size + 1): validList.append(i) return validList

def contains_only_valid_symbols(puzzle, complete): size = get_size(puzzle) validList = get_valid_numbers(size) if complete == False: validList.append(None) for row in puzzle: for element in row: if element not in validList: return False return True

def has_repeat(xs, v): count = 0 for i in xs: if i == v: count += 1 if count > 1: return True else: return False

def get_row(puzzle, row_index): size = get_size(puzzle) if row_index + 1 > size: return None return puzzle[row_index]

Python 3 Coding: Here is the code I have finished for theother half of the project. This is relevant because some of the

complete): given a puzzle, determine if the row at row index is a is valid row(puzzle row index valid set of numbers (containing only valid values and unique values). complete is a boolean indicating if the row may contain None values. As before, if the puzzle is incomplete, also allow None, if it is complete, do not allow None. Also note that it is OK to have multiple None values in one row. (HINT use get valid numbers get row() and has repeat [2,4,None ,None 1,[1, 2,3,3],[3,1 ,None,5],[4,3 ,None, None board is valid row (board, 0, False) True ok to have None if incomplete is valid row (board, 0 True) False cannot have None if complete is valid row (board, 1, True False two 3s in same ro is valid row(board, 2 False) False invalid value 5 is valid row(board, 2, True False not even a valid ro complete): determine if all the rows in puzzle are valid. complete is a boolean has valid rows (puzzle indicating if the rows should not contain None values. If incomplete allow None, if complete, do not allow None. (HINT: use get row() and is valid row() as part of your solution) has valid rows [1, 2],[1,21], True True has valid rows ([[1, None],[1,21], False) True has valid rows ([[1,None 1,[1, 211, True False cannot have None if complete has valid rows([[1,4],[ 1,211, True) False row 0 has a 4 in a 2x2 puzzle get column (puzzle col index) return the column with specified col index from puzzle as a list. Return None if col index is invalid get column ([[1,None],[2,Nonell, 0) [1 col 0 get column ([[1,None 1,[2,None 11, 1) [None, None] col 1 get column ([[1,None 1,[2,None] 1, 2) invalid index None complete) similar to is valid row but checking the validity of is valid col (puzzle col index specified column instead. (HINT: use get valid numbers get column and has repeat().) [2,1,None ,None ],[None, 2,3,3],[3, 1, None,5],[4,3,None,None board is valid col(board, 0, False) True ok to have None if incomplete is valid col (board, 0, True) False cannot have None if complete is valid col board, 1 True) False two 1s in same column is valid col(board, 3, False) False invalid value 5 is valid col(board, 7 True False not even a valid column complete): determine if all the columns in puzzle are valid. complete is a has valid cols (puzzle boolean indicating if the columns may contain None values. If incomplete allow None, if complete, do not allow None. (HINT use is valid col() and get column() as part of your solution) has valid cols ([[1,2],[1,1]], True) False two 1s in col 0 has valid cols([[1,None],[2,11], False) True has valid None ],[2,111, True) False cannot have None if complete has valid cols([[1,4],[2,11], False col 1 has a 4 in a 2x2 puzzle True complete): given a puzzle, determine if the row at row index is a is valid row(puzzle row index valid set of numbers (containing only valid values and unique values). complete is a boolean indicating if the row may contain None values. As before, if the puzzle is incomplete, also allow None, if it is complete, do not allow None. Also note that it is OK to have multiple None values in one row. (HINT use get valid numbers get row() and has repeat [2,4,None ,None 1,[1, 2,3,3],[3,1 ,None,5],[4,3 ,None, None board is valid row (board, 0, False) True ok to have None if incomplete is valid row (board, 0 True) False cannot have None if complete is valid row (board, 1, True False two 3s in same ro is valid row(board, 2 False) False invalid value 5 is valid row(board, 2, True False not even a valid ro complete): determine if all the rows in puzzle are valid. complete is a boolean has valid rows (puzzle indicating if the rows should not contain None values. If incomplete allow None, if complete, do not allow None. (HINT: use get row() and is valid row() as part of your solution) has valid rows [1, 2],[1,21], True True has valid rows ([[1, None],[1,21], False) True has valid rows ([[1,None 1,[1, 211, True False cannot have None if complete has valid rows([[1,4],[ 1,211, True) False row 0 has a 4 in a 2x2 puzzle get column (puzzle col index) return the column with specified col index from puzzle as a list. Return None if col index is invalid get column ([[1,None],[2,Nonell, 0) [1 col 0 get column ([[1,None 1,[2,None 11, 1) [None, None] col 1 get column ([[1,None 1,[2,None] 1, 2) invalid index None complete) similar to is valid row but checking the validity of is valid col (puzzle col index specified column instead. (HINT: use get valid numbers get column and has repeat().) [2,1,None ,None ],[None, 2,3,3],[3, 1, None,5],[4,3,None,None board is valid col(board, 0, False) True ok to have None if incomplete is valid col (board, 0, True) False cannot have None if complete is valid col board, 1 True) False two 1s in same column is valid col(board, 3, False) False invalid value 5 is valid col(board, 7 True False not even a valid column complete): determine if all the columns in puzzle are valid. complete is a has valid cols (puzzle boolean indicating if the columns may contain None values. If incomplete allow None, if complete, do not allow None. (HINT use is valid col() and get column() as part of your solution) has valid cols ([[1,2],[1,1]], True) False two 1s in col 0 has valid cols([[1,None],[2,11], False) True has valid None ],[2,111, True) False cannot have None if complete has valid cols([[1,4],[2,11], False col 1 has a 4 in a 2x2 puzzle True

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 Databases Questions!