题解 | #密码强度等级# 好多if elif。。。。。。。

密码强度等级

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

def Score(s):
    score=0

    # 密码长度得分
    if len(s)<=4:
        score += 5
    elif 5<=len(s)<=7:
        score += 10
    elif len(s)>=8:
        score += 25

    # 字母得分
    LETTER=''.join(i for i in s if 65<=ord(i)<=90)
    n_LETTER=len(LETTER)
    letter=''.join(i for i in s if 97<=ord(i)<=122)
    n_letter=len(letter)
    #print(n_LETTER,n_letter)
    if n_LETTER==0 and n_letter==0:
        score += 0
    elif (n_LETTER>0 and n_letter==0) or (n_LETTER==0 and n_letter>0):
        score += 10
    elif n_LETTER>0 and n_letter>0:
        score += 20

    # 数字得分
    num=''.join(i for i in s if 48<=ord(i)<=57)
    n_num=len(num)
    if n_num==0:
        score += 0
    elif n_num==1:
        score += 10
    elif n_num>1:
        score += 20

    # 符号得分
    asc=list(range(1,128))
    #print(asc)
    symbol_ascii=[ii for ii in asc if ii not in asc[47:57] and ii not in asc[64:90] and ii not in asc[96:122]]
    symbol=''.join(i for i in s if ord(i) in symbol_ascii)
    n_symbol=len(symbol)
    if n_symbol==0:
        score += 0
    elif n_symbol==1:
        score += 10
    elif n_symbol>1:
        score += 25
    
    # 奖励得分
    if n_LETTER!=0 and n_letter==0 and n_num!=0 and n_symbol==0:
        score += 2
    elif n_LETTER==0 and n_letter!=0 and n_num!=0 and n_symbol==0:
        score += 2
    elif n_LETTER==0 and n_letter!=0 and n_num!=0 and n_symbol!=0:
        score += 3
    elif n_LETTER!=0 and n_letter==0 and n_num!=0 and n_symbol!=0:
        score += 3
    elif n_LETTER!=0 and n_letter!=0 and n_num!=0 and n_symbol!=0:
        score += 5

    return score   # 必须return得分,否则下一个函数无法生效

def SecurityLevel(score):
    if 0<=score<25:
        print('VERY_WEAK')
    elif 25<=score<50:
        print('WEAK')
    elif 50<=score<60:
        print('AVERAGE')
    elif 60<=score<70:
        print('STRONG')
    elif 70<=score<80:
        print('VERY_STRONG')
    elif 80<=score<90:
        print('SECURE')
    elif score>=90:
        print('VERY_SECURE')


while 1:
    try:
        s=input()
        s_score=Score(s)
        SecurityLevel(s_score)
    except:
        break

全部评论

相关推荐

dongsheng66:如果想进大厂的话,在校经历没必要占这么大篇幅,可以把专业技能单独放一个专栏写,可以加个项目经历
点赞 评论 收藏
分享
有工作后先养猫:太好了,是超时空战警,我们有救了😋
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务