IndentationError:预期缩进块中的缩进块

时间:2017-04-02 19:48:26

标签: python python-2.7 indentation

我的代码中有问题我不知道如何修复 我甚至试图在同一行中放置5个缩进但它没有帮助 如果我在这里错了可以有人重写我的代码,所以它会工作吗?我已经坐了大约40米,仍然无法找出问题,谢谢!

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("[~\!@#\$%\^&\*\(\)_\+{}\":;'\[\]]", 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()

1 个答案:

答案 0 :(得分:0)

这是一个愚蠢的错误,你忘了导入重新。这工作

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("[~\!@#\$%\^&\*\(\)_\+{}\":;'\[\]]", 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()
相关问题