题解 | #密码强度等级#

密码强度等级

http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

while True:
    try:
        s = input()
        score = 0
        #lenth
        if len(s) <= 4:
            score += 5
        elif 5 <= len(s) <= 7:
            score += 10
        else:
            score += 25
        #print(score)
        #alph
        res = []
        for i in s:
            if i.isalpha():
                res.append(i)
        res = ''.join(res)
        #print(res)
        if res == '':
            score += 0
        else:
            if res.islower():
                score += 10
            elif res.isupper():
                score += 10
            else:
                score += 20
        #print(score)
        #number
        k = 0
        for i in s:
            if i.isnumeric():
                k += 1
        if k == 1:
            score += 10
        elif k > 1:
            score += 20
        #print(score)
        #str
        slst = ['!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~']
        k1 = 0
        for i in s:
            if i in slst:
                k1 += 1
        if k1 == 0:
            score += 0
        elif k1 == 1:
            score += 10
        else:
            score += 25
        #print(score)
        #bonus
        if k != 0 and k1 != 0:
            if len(res) != 0:
                if res.isupper() or res.islower():
                    score += 3
                else:
                    score += 5
        elif k != 0 and (res.islower() or res.isupper()):
            score += 2
        #print(score)
        #print
        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')
        else:
            print('VERY_WEAK')
        #print(score)
    except:
        break
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务