题解 | #密码强度等级#

密码强度等级

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

全部评论

相关推荐

05-10 16:48
门头沟学院 Java
程序员小白条:主要原因,投递太晚了,快手应该早点溜了,你都从去年9月开始的,半年也差不多3月跑路了,这样的话,至少有5个以上的面试机会
点赞 评论 收藏
分享
03-26 13:04
已编辑
电子科技大学 算法工程师
xiaowl:你这个简历“条目上”都比较有深度性,但是实际上面试官又没法很好的评估你是怎么达到很多看上去很厉害的结果的。要避免一些看上去很厉害的包装,比如高效的内存复用策略的表达,如果仅是简单的一些内存共享机制,而且面试上也没有深挖的空间,就不要这样表达。比如,工程化模式本质上可能就是定义了一些abstract class,那也就没特别多值得讲的内容。建议简历上应该侧重那些你花了大量时间和精力解决、研究的问题,不要过分追求“丰富”,而是关注在技术深入度、问题解决能力的表现上。
没有实习经历,还有机会进...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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