题解 | #密码强度等级#

密码强度等级

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

全部评论

相关推荐

榕城小榕树:1200单休,我去干点啥别的不好
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 11:15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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