Python题解 | #密码强度等级#

密码强度等级

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

import sys


while True:
    try:
        s = input()
        l, w, d, c = 0, 0, 0, 0
        if len(s) <= 4:
            l = 5
        elif 5 <= len(s) <= 7:
            l = 10
        elif len(s) >= 8:
            l = 25
        
        a = [0] * 2
        num = 0
        ch = 0
        for i in s:
            if i.isupper():
                a[0] += 1
            elif i.islower():
                a[1] += 1
            elif i.isdigit():
                num += 1
            else:
                ch += 1
        
        if (num + ch) == len(s):
            w = 0
        elif a[0] + (num + ch) == len(s) or a[1] + (num + ch) == len(s):
            w = 10
        elif a[0] != 0 and a[1] != 0:
            w = 20
        

        if num == 0:
            d = 0
        elif num == 1:
            d = 10
        elif num > 1:
            d = 20

        if ch == 0:
            c = 0
        elif ch == 1:
            c = 10
        elif ch > 1:
            c = 25
        
        j = 0
        if (a[0] != 0 and num != 0) or (a[1] != 0 and num != 0):
            j = 2
        if (a[0] != 0 and num != 0 and ch != 0) or (a[1] != 0 and num != 0 and ch != 0):
            j = 3
        if a[0] != 0 and a[1] != 0 and num != 0 and ch != 0:
            j = 5
        
        sum_score = l + w + d + c + j
        if sum_score >= 90:
            print('VERY_SECURE')
        elif 90 > sum_score >= 80:
            print('SECURE')
        elif 80 > sum_score >= 70:
            print('VERY_STRONG')
        elif 70 > sum_score >= 60:
            print('STRONG')
        elif 60 > sum_score >= 50:
            print('AVERAGE')
        elif 50 > sum_score >= 25:
            print('WEAK')
        else:
            print('VERY_WEAK')


        
        

    except:
        break

全部评论
不必理会
点赞 回复 分享
发布于 2024-05-17 23:24 上海

相关推荐

这算盘打的
程序员小白条:都这样的,都是潜规则,你自己说可以实习一年就行了,实习可以随便跑路的
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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