HJ87 密码强度等级

思路:

按题目要求对应书写即可

代码如下:

while True:
    try:
        s = input()
        score = 0
        
        #长度:
        if len(s) <= 4:
            score = score + 5
        elif 5 <= len(s) <= 7:
            score = score + 10
        elif len(s) >= 8:
            score = score + 25
        
        #字母:
        isu = 0
        isl = 0
        for i in s:
            if 'A' <= i <= 'Z':
                isu = 1
        for i in s:
            if 'a' <= i <= 'z':
                isl = 1
        score = score + 10 * (isu + isl)
        
        #数字:
        shuzi = '0123456789'
        count1 = 0
        for i in s:
            if i in shuzi:
                count1 += 1
        if count1 == 1:
            score = score + 10
        elif count1 > 1:
            score = score + 20
        
        #符号:
        fuhao = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
        count2 = 0
        for i in s:
            if i in fuhao:
                count2 += 1
        if count2 == 1:
            score = score + 10
        elif count2 > 1:
            score = score + 25
        
        #奖励:
        if (isu + isl) == 2 and count1 >= 1 and count2 >= 1:
            score = score + 5
        elif (isu + isl) == 1 and count1 >= 1 and count2 >= 1:
            score = score + 3
        elif (isu + isl) == 1 and count1 >= 1:
            score = score + 2
        
        #评分:
        if score >= 90:
            print('VERY_SECURE')
        elif score >= 80:
            print('SECURE')
        elif score >= 70:
            print('VERY_STRONG')
        elif score >= 60:
            print('STRONG')
        elif score >= 50:
            print('AVERAGE')
        elif score >= 25:
            print('WEAK')
        elif score >= 0:
            print('VERY_WEAK')
    except:
        break