IndentationError:预计在缩进块的缩进块

问题描述:

我在我的代码中的问题,我不知道如何解决 我甚至试图把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

它的一个愚蠢的错误,你忘了导入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