首页 文章

IndentationError:unindent与任何外部缩进级别python都不匹配

提问于
浏览
1

你好,这是我的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)

当我尝试编译此代码时,我遇到了错误:produit = ijz ^ IndentationError:unindent与任何外部缩进级别都不匹配任何人都有想法吗?

3 回答

  • 0

    你问题中的代码是一团糟 . 这是修复缩进后的样子 .

    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)
    
  • -1

    您还可以在命令行中检查选项卡/空格的问题:

    python -m tabnanny -v yourfile.py
    
  • 3

    这是您需要的代码

    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)
    

相关问题