0

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

2 Answers 2

1

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):

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for the help.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.