题解 | #密码强度等级#

in_str = input()
fin_score = 0

#统计长度
len_score = 0
if len(in_str) <= 4:
    len_score = 5
elif 5 <= len(in_str) <= 7:
    len_score = 10
elif 8 <= len(in_str):
    len_score = 25

# 统计字母 和 数字
chr_score = 0
num_score = 0
cn_low_chr = 0
cn_upp_chr = 0
cn_num = 0
cn_oth = 0
for i in in_str:
    if i.isdigit():
        cn_num += 1
    elif i.islower():
        cn_low_chr += 1
    elif i.isupper():
        cn_upp_chr += 1

if cn_low_chr == 0 and cn_upp_chr == 0:
    chr_score = 0
elif cn_low_chr > 0 and cn_upp_chr == 0:
    chr_score = 10
elif cn_low_chr == 0 and cn_upp_chr > 0:
    chr_score = 10
elif cn_low_chr > 0 and cn_upp_chr > 0:
    chr_score = 20

if cn_num == 0:
    num_score = 0
elif cn_num == 1:
    num_score = 10
elif cn_num > 1:
    num_score = 20

# 符号
oth_score = 0
cn_oth = len(in_str) - cn_low_chr - cn_upp_chr - cn_num
if cn_oth == 0:
    oth_score = 0
elif cn_oth == 1:
    oth_score = 10
elif cn_oth > 1:
    oth_score = 25

# 奖励
jl_score = 0
if chr_score == 20 and num_score > 0  and oth_score > 0:
    jl_score = 5
elif chr_score == 10 and num_score > 0 and oth_score > 0:
    jl_score = 3
elif chr_score == 10 and num_score > 0:
    jl_score = 2

fin_score = len_score + chr_score + num_score + oth_score + jl_score
re = ''
if fin_score >= 90:
    re = 'VERY_SECURE'
elif 80 <= fin_score < 90:
    re = 'SECURE'
elif 70 <= fin_score < 80:
    re = 'VERY_STRONG'
elif 60 <= fin_score < 70:
    re = 'STRONG'
elif 50 <= fin_score < 60:
    re = 'AVERAGE'
elif 25 <= fin_score < 50:
    re = 'WEAK'
elif 0 <= fin_score < 25:
    re = 'VERY_WEAK'
print(re)
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 10:48
点赞 评论 收藏
分享
10-18 13:01
已编辑
西安理工大学 C++
小米内推大使:建议技能还是放上面吧,hr和技术面试官第一眼想看的应该是技能点和他们岗位是否匹配
点赞 评论 收藏
分享
美团 后端开发 总包n(15%是股票)
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务