Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HELP Python 3 Functions Coding: Below are the functions required to fully comple

ID: 3808947 • Letter: H

Question

HELP Python 3 Functions Coding: Below are the functions required to fully complete the functions

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

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

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

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, ifthe 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, 2, 3,3],[ board ,3,None, None 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 row is valid row (board, 2 False) False invalid value 5 is valid row(board 2, True) False not even a valid row complete) determine if all the rows in puzzle are valid complete is a boolean has valid rows (puzzle ndicating if the rows should not contain None values. If incomplete allow None, if complete, do not allow None. (HINT and is valid row as part of your solution) use get row has valid rows ([[1,2],[1,21 True True has valid rows (CC1,None],[1,21] False) True has valid rows ([[1,None],[1, 211, True) False cannot have None if complete has valid rows ([[1,4],[1,21], True False row 0 has a 4 in a 2x2 puzzle col index): return the column with specified col index from puzzle as a list get column (puzzle Return None if col index is invalid get column ([[1, None],[2, Nonell, 0) [1 21 col 0 get column [1,None],[2,None]], 1) [None, None] col 1 get column([ [1,None],[2,None]], 2) None invalid index 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 repea board [[2,1,None,None],[None, 2,3,3],[3, 1,None,5],[4,3,None,None]] 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, False not even a valid column True 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 (CC1,2],[1,11], True False two in col 0 has valid cols([[1,None],[2,11] False) True has valid cols ([[1,None ],[2,111, True False cannot have None if complete has valid cols ([[1,4], [2,111, True False col 1 has a 4 in a 2x2 puzzle

Explanation / Answer

Code :

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

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

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 is_valid_row(puzzle, row_index,complete):
   lst = get_row(puzzle,row_index)
   if lst == None :
       return False
   if max(lst) > len(lst):
       return False
   for i in lst :
       if complete == True and i == None :
           return False
       else :
           if i!= None and has_repeat(lst,i) :
               return False
   return True

def has_valid_rows(puzzle,complete):
   size = get_size(puzzle)
   for i in range(size):
       if is_valid_row(puzzle,i,complete) == False:
           return False
   return True

def get_size(puzzle):
   return len(puzzle)

def get_column(puzzle,col_index):
   size = get_size(puzzle)
   if col_index + 1 > size:
       return None
   lst = []
   for i in range(size):
       lst.append(puzzle[i][col_index])
   return lst

def is_valid_col(puzzle,col_index,complete):
   lst = get_column(puzzle,col_index)
   if lst == None :
       return False
   if max(lst) > len(lst):
       return False
   for i in lst :
       if complete == True and i == None :
           return False
       else :
           if i!= None and has_repeat(lst,i) :
               return False
   return True

def has_valid_cols(puzzle,complete):
   size = get_size(puzzle)
   for i in range(size):
       if is_valid_col(puzzle,i,complete) == False:
           return False
   return True

#puzzle = [[2,4,None,None],[1,2,3,3],[3,1,None,5],[4,3,None,None]]
#print is_valid_row(puzzle,-2,False)
#print has_valid_rows([[1,None],[2,1]],True)
#print get_column([[1,None],[2,None]],2)
#print is_valid_col(puzzle,4,False)

Please let me know incase of any issues.