2016-01-27 102 views
1

你好,這裏是我的Python代碼:IndentationError:取消縮進不匹配任何外部縮進級別蟒蛇

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 =我Ĵž ^ IndentationError:unindent不匹配任何外部縮進級別 任何人有一個想法,請??

+5

我有問題的思路:取消縮進沒有按不匹配任何外部縮進級別。縮進在Python中很重要,所以你必須修復它。檢查您每個級別使用多少個空間,檢查是否有任何標籤,等等。 – TigerhawkT3

+0

事實上:程序正在工作,但是當我在範圍(j,1000)中添加z時:我乘以i和j乘以z我得到了錯誤 – nour

+0

我不明白爲什麼 – nour

回答

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

這是你所需的代碼

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) 
+0

我看到一個unindent不匹配任何外部縮進級別。這不會運行。 – TigerhawkT3

3

您可以檢查與選項卡/空格也在命令行的問題:

python -m tabnanny -v yourfile.py 
相關問題