题解 | #密码强度等级#

密码强度等级

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

def func(str1):
    if len(str1) <=4:
        return 5
    elif 5<=len(str1)<=7:
        return 10
    else:
        return 25
    
def func2(str1):
    nozimu_flag = True
    for i in str1:
        if i.isalpha():
            nozimu_flag = False
    if nozimu_flag:
        return 0
    daxie = False
    xiaoxie = False
    for i in str1:
        if i.isalpha():
            if 'a'<=i<='z':
                xiaoxie = True
            if 'A'<=i<='Z':
                daxie = True
    if daxie and xiaoxie:
        return 20
    elif daxie or xiaoxie:
        return 10
    
def func3(str1):
    counter = 0
    for i in str1:
        if i.isdigit():
            counter += 1

    if counter == 0:
        return 0
    elif counter == 1:
        return 10
    elif counter >1:
        return 20
    
def func4(str1):
    fuhao = list(range(int('0x21',16),int('0x2F',16)+1)) 
    fuhao = fuhao +  list(range(int('0x3A',16),int('0x40',16)+1))
    fuhao = fuhao +  list(range(int('0x5B',16),int('0x60',16)+1))
    fuhao = fuhao +  list(range(int('0x7B',16),int('0x7E',16)+1))

    counter = 0
    for i in str1:
        if ord(i) in fuhao:
            counter += 1
    if counter == 0 :
        return 0
    elif counter == 1:
        return 10
    elif counter >1:
        return 25
        
def func5(str1):
    if func2(str1) == 20 and func3(str1) != 0 and func4(str1) != 0:
        return 5
    if func2(str1) != 0 and func3(str1) != 0 and func4(str1) != 0:
        return 3
    if func2(str1) != 0 and func3(str1) != 0 :
        return 2
    else:
        return 0

str1 = input()
s = func(str1) + func2(str1) + func3(str1) + func4(str1) + func5(str1)
# print(func(str1) , func2(str1) , func3(str1) , func4(str1) , func5(str1))

if s >= 90:
    print('VERY_SECURE')
elif s>=80:
    print('SECURE')
elif s>=70:
    print('VERY_STRONG')
elif s>=60:
    print('STRONG')
elif s>=50:
    print('AVERAGE')
elif s>=25:
    print("WEAK")
elif s>=0:
    print('VERY_WEAK')

全部评论

相关推荐

勇敢的联想人前程似锦:如果我是你,身体素质好我会去参军,然后走士兵计划考研211只需要200多分。
点赞 评论 收藏
分享
斑驳不同:还为啥暴躁 假的不骂你骂谁啊
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务