python - Testing for non-integers (decimals and strings) -


hi i'm having trouble testing non-integers in sript. i'm trying write function returns true if sudoku valid , false if not. 2 rule sudoku: 1) each column of square contains each of whole numbers 1 n once. 2) each row of square contains each of whole numbers 1 n once. problem i'm having functions "incorrect4" , "incorrect5". incorrect4 showing true though it's not integer/whole number , incorrect5 display error message: unsupported operand type(s) +: 'int' , 'str'. i've tried multiple ways of testing integers value of "1.5" in incorrect4 still shows true. additionally i've looked solution unsupported operand type error unable fix it. know there other, more efficient ways solve issue appreciated!

correct = [[1,2,3],        [2,3,1],        [3,1,2]] incorrect4 = [['a','b','c'],           ['b','c','a'],           ['c','a','b']]  incorrect5 = [ [1, 1.5],            [1.5, 1]]  def check_sudoku(square):     = 0     result = [sum(l) l in square]     sum_list = []      all(type(item)==int item in square)     return true      col in range(len(square[0])):         sum_list.append(sum(row[col] row in square))         if sum_list == result: return true     return false       row in range(len(square)):         if sum(square[a]) == sum(square[a+1]):             += 1             return true     return false  print check_sudoku(correct) print check_sudoku(incorrect4) print check_sudoku(incorrect5) 

since sudoku puzzles must have integers between 1-9, don't want other crazy integers -4294967296 passing through. ergo, think check appropriate:

d = 3  # edge-size of sudoku all(n in range(1, d**2) row in sudoku_puzzle n in row) 

where sudoku_puzzle can list of lists, might consider using numpy arrays instead.

you still need check make sure dimensions of sudoku_puzzle correct.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -