题解 | #密码强度等级#

密码强度等级

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

# for line in sys.stdin:
#     a = line.split()
#     print(int(a[0]) + int(a[1]))


# 长度len 字母isupper islower isalpha
# 数字isdigit 符号!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~
# 奖励reward

# 利用函数的方法解决
# 长度得分
def psw_len(str):
    if len(str) >= 8:
        return 25
    elif len(str) >= 5:
        return 10
    else:
        return 5


# 字母得分
def alpha_score(str):
    score_upper,score_lower = 0,0   #初始化数据防止出现加不存在的数据
    for i in str:
        if i.isupper():
            score_upper = 10
            break
    for i in str:
        if i.islower():
            score_lower = 10
            break
    return score_upper + score_lower


# 数字得分
def digit_score(str):
    tmp = 0
    for i in str:
        if i.isnumeric():
            tmp = tmp + 10
            if tmp == 20:
                break
    return tmp


# 符号得分
def symbol_score(str):
    tmp = 0
    for i in str:
        bsymbol = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
        if i in bsymbol:
            tmp = tmp + 10
            if tmp == 20:
                tmp = 25
                break
    return tmp


# 奖励的分数
def reward_score(alpha_score, digit_score, symbol_score):
    if (
        alpha_score == 20 and digit_score != 0 and symbol_score != 0
    ):  # 条件语句中不能用%代替and关键字
        return 5
    elif alpha_score != 0 and digit_score != 0 and symbol_score != 0:
        return 3
    elif alpha_score != 0 and digit_score != 0:
        return 2
    else:
        return 0


while True:
    try:
        str = input()
        psw_score = psw_len(str)
        alpha_score = int(alpha_score(str))
        digit_score = int(digit_score(str))
        symbol_score = int(symbol_score(str))
        reward_score = int(reward_score(alpha_score, digit_score, symbol_score))
        score = int(psw_score + alpha_score + digit_score + symbol_score + reward_score)
        # 评分标准
        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")
    except:
        break

全部评论

相关推荐

点赞 评论 收藏
分享
渐好:软光栅真的写明白了吗,既然是软渲那技术栈不应该使用OpenGL,光追和bvh既不算什么高级渲染技术更不应该属于软渲的内容,git那个项目没啥用,建议把前两个项目重新组织一下语言,比如软渲染那个项目 冯着色和msaa、贴图这几项分开写,写的到位点,如果你还学过光追那就单独写出来,如果没把握考官问你答不上来就别写给自己找麻烦,在技术栈那一栏简单提一下自己学过就行,这样杂的放在一起不太严谨,个人愚见.
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务