2017-04-02 56 views
-2

我在我的代碼中的問題,我不知道如何解決 我甚至試圖把5個縮進在同一行但它沒有幫助 如果我錯了這裏有人可以重寫我的代碼,所以它會起作用嗎?我已經坐了大約40米,仍然無法找出問題,謝謝!IndentationError:預計在縮進塊的縮進塊

def grade_len(password): 
    if(len(password) <= 4): 
     return 0 
    if(5 <= len(password) <= 7): 
     return 5 
    if(len(password) > 7): 
     return 10 

def grade_used(password): 
    if(password[0:9] == 'password' or 'love' in password or 'qwerty' in password or 'abc' in password): 
     return 0 
    else: 
     return 10 



def grade_vari(password): 
    if(re.search('[a-z]',password) == False): 
     return 0 
    if(password.isalpha()): 
     return 3 
    if(password.lower == password.lower and password.isalpha() == False): 
     return 5 
    if(re.search('[a-z]',password) and re.search('[A-Z]',password) and re.search('[0-9]',password)): 
     return 7 
    if(re.search('[0-9]',password) and re.search('[a-z]',password) and re.search('[A-Z]',password) and re.match("[~\[email protected]#\$%\^&\*\(\)_\+{}\":;'\[\]]", password)): 
     return 10 




def main(): 
    password = raw_input ("enter password:") 
    test1 = grade_len(password) 
    test2 = grade_used(password) 
    test3 = grade_vari(password) 
    test_num = 3 
    test_average = (test1+test2+test3)/3 
    if(test_average<4): 
     print("Weak") 
    if(4<=test_average<=6): 
     print("Medium") 
    if(7<=test_average<=8): 
     print("Strong") 
    if(9<=test_average<=10): 
     print("Very strong")  

main() 
+0

你是否在你的文件中導入了're'? –

+0

您的代碼適用於我 – alDiablo

+1

您應該爲一個級別的縮進使用4個空格。一致 - 每個縮進級別總是4個空格。 可能出現此錯誤,因爲在一個地方,您有一個空間可以更少或更多。看看你的代碼中沒有混合製表符和空格(一個好的IDE應該處理這個)。 – bodolsog

回答

0

它的一個愚蠢的錯誤,你忘了導入re。這個作品

import re 
def grade_len(password): 
    if(len(password) <= 4): 
     return 0 
    if(5 <= len(password) <= 7): 
     return 5 
    if(len(password) > 7): 
     return 10 

def grade_used(password): 
    if(password[0:9] == 'password' or 'love' in password or 'qwerty' in password or 'abc' in password): 
     return 0 
    else: 
     return 10 



def grade_vari(password): 
    if(re.search('[a-z]',password) == False): 
     return 0 
    if(password.isalpha()): 
     return 3 
    if(password.lower == password.lower and password.isalpha() == False): 
     return 5 
    if(re.search('[a-z]',password) and re.search('[A-Z]',password) and re.search('[0-9]',password)): 
     return 7 
    if(re.search('[0-9]',password) and re.search('[a-z]',password) and re.search('[A-Z]',password) and re.match("[~\[email protected]#\$%\^&\*\(\)_\+{}\":;'\[\]]", password)): 
     return 10 




def main(): 
    password = raw_input ("enter password:") 
    test1 = grade_len(password) 
    test2 = grade_used(password) 
    test3 = grade_vari(password) 
    test_num = 3 
    test_average = (test1+test2+test3)/3 
    if(test_average<4): 
     print("Weak") 
    if(4<=test_average<=6): 
     print("Medium") 
    if(7<=test_average<=8): 
     print("Strong") 
    if(9<=test_average<=10): 
     print("Very strong") 

main() 
+0

謝謝!我是python的新手。這是我的第五個程序,我對所有的圖書館都不太瞭解。非常感謝你!你爲我節省了很多時間 – user7355747

+0

我知道學習是一個艱難的過程,確保你使用像Pycharm這樣的IDE或者其他的東西(選擇你最喜歡的)。這是一個可以被IDE捕獲的簡單錯誤。你可以從這裏下載社區版https://www.jetbrains.com/pycharm/ ..好運與編程:) – rrmerugu

相關問題