Search code examples
pythonpython-2.7python-3.xwxpythonipython

IndentationError: unindent does not match any outer indentation level python


Hello here is my python code:

def is_palindrome(nombre):
    if str(nombre) == str(nombre)[::-1]:
        return True
    return False
x = 0
for i in range(100, 1000):
    for j in range(i, 1000):
        for z in range(j, 1000):    
 produit = i*j*z

        if is_palindrome(produit):
            if produit > x:
                x = produit
print(x)

When I tried to compile this code I have got that error: produit = ijz ^ IndentationError: unindent does not match any outer indentation level Anyone has an idea please??


Solution

  • The code in your question is a mess. Here's how it could probably look like with the indentation fixed.

    def is_palindrome(nombre):
        if str(nombre) == str(nombre)[::-1]:
            return True
        return False
    
    x = 0
    for i in range(100, 1000):
        for j in range(i, 1000):
            for z in range(j, 1000):    
                produit = i*j*z
    
                if is_palindrome(produit):
                    if produit > x:
                        x = produit
    # you may want to move this into the inner `if` statement
    print(x)