题解 | #密码强度等级#

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

def length(s):
    lenth = len(s)
    if lenth <= 4:
        return 5
    elif 5 <= lenth <= 7:
        return 10
    else:
        return 25


def alp(s):
    global char_l
    char_l = 0
    global char_u
    char_u = 0
    global num
    num = 0
    global sign
    sign = 0
    for c in s:
        if c.isupper() == True:
            char_u += 1
        elif c.islower() == True:
            char_l += 1
        elif c.isdigit() == True:
            num += 1
        elif c in "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~":  # 将"和\转义
            sign += 1
    if (char_l + char_u) == 0:
        return 0
    elif char_l == 0 and char_u != 0:
        return 10
    elif char_u == 0 and char_l != 0:
        return 10
    elif char_u * char_l > 0:
        return 20


def digit(s):
    if num == 0:
        return 0
    elif num == 1:
        return 10
    elif num > 1:
        return 20


def sig(s):
    if sign == 0:
        return 0
    elif sign == 1:
        return 10
    elif sign > 1:
        return 25


def reward(s):
    if sign == 0 and num != 0 and char_l + char_u != 0:
        return 2
    elif sign != 0 and num != 0 and char_l * char_u != 0:
        return 5
    elif sign != 0 and num != 0 and char_l + char_u != 0:
        return 3
    else:
        return 0


def final_mark(s):
    countscore = int(length(s))+int(alp(s))+int(digit(s))+int(sig(s))+int(reward(s))
    if countscore>=90:
        print("VERY_SECURE")
    if 80<=countscore<90:
        print("SECURE")
    if 70<=countscore<80:
        print("VERY_STRONG")
    if 60<=countscore<70:
        print("STRONG")
    if 50<=countscore<60:
        print("AVERAGE")
    if 25<=countscore<50:
        print("WEAK")
    if 0<=countscore<25:
        print("VERY_WEAK")


s = input()
final_mark(s)
全部评论

相关推荐

dongsheng66:如果想进大厂的话,在校经历没必要占这么大篇幅,可以把专业技能单独放一个专栏写,可以加个项目经历
点赞 评论 收藏
分享
美团 后端开发 总包n(15%是股票)
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务