IndentationError: unindent does not match any outer indentation level python

IndentationError: unindent does not match any outer indentation level python

你好,这是我的 python 代码:

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)

当我尝试编译这段代码时出现了错误: 产品 = ijz ^ IndentationError: unindent 不匹配任何外部缩进级别 有人有想法吗??

你问题中的代码乱七八糟。这是固定缩进后的样子。

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)

您也可以在命令行中检查 tabs/spaces 的问题:

python -m tabnanny -v yourfile.py