Reputation: 13
I'm trying to create sudoku, but I'm getting this error. I think it's because of the range
line; maybe I'm doing it wrong, but range(int(numb/numb+3))
doesn't really work either. Thanks for the help.
File "D:\Games\Python\sudokuV2Test2.py", line 83, in estDansSousMatrice
for i in range(bl, bl+3):
TypeError: 'float' object cannot be interpreted as an integer"
This is the code:
def estDansSousMatrice(grille,l,c,v):
bc=(c/3)*3
bl=(l/3)*3
for i in range(bl, bl+3):
for j in range(bc,bc+3):
if grille[i][j]==v:
return True
return False
Upvotes: 0
Views: 6503
Reputation: 8829
To be clear, you can sidestep the converting back to int
by never making them floats in the first place. The //
operator performs integer division, truncating the result. This lets you keep almost all of your original code.
def estDansSousMatrice(grille,l,c,v):
bc=(c//3)*3 # Different
bl=(l//3)*3 # Different
for i in range(bl, bl+3):
for j in range(bc,bc+3):
if grille[i][j]==v:
return True
return False
Upvotes: 0
Reputation: 61
Since your previously dividing bc
and bl
and then multiplying by 3, say we input c = 3
and l = 3
the outcomes for both of those would be 3.0
instead do for i in range(int(bl),int(bl)+3):
and for j in range(int(bc),int(bc)+3):
Upvotes: 1