题解 | #密码强度等级#

密码强度等级

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

import re

key = input()
score = 0
t = []
# 一、密码长度:
if len(key) <= 4:
    score += 5
elif 4 < len(key) <= 7:
    score += 10
else:
    score += 25
# print(score)
# 二、字母:
if len(re.findall("[a-zA-Z]", key)) == 0:
    score += 0
elif len(re.findall("[a-z]", key)) != 0 and len(re.findall("[A-Z]", key)) != 0:
    score += 20
    t.append(5)
else:
    score += 10
    t.append(2)
    t.append(3)
# print(score)
# 三、数字:
if len(re.findall("[0-9]", key)) == 0:
    score += 0
elif len(re.findall("[0-9]", key)) == 1:
    score += 10
    t.append(2)
    t.append(3)
    t.append(5)
else:
    score += 20
    t.append(2)
    t.append(3)
    t.append(5)
# print(score)
# 四、符号:
if len(re.findall("[^0-9a-zA-Z]", key)) == 0:
    score += 0
elif len(re.findall("[^0-9a-zA-Z]", key)) == 1:
    score += 10
    t.append(3)
    t.append(5)
else:
    score += 25
    t.append(3)
    t.append(5)
# print(score)
# 五、奖励(只能选符合最多的那一种奖励):
# print(t)
if t.count(5) == 3:
    score += 5
elif t.count(3) == 3:
    score += 3
elif t.count(2) == 2:
    score += 2
else:
    score += 0
# print(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")

全部评论

相关推荐

Hyh_111:像这种hr就不用管了,基本没啥实力,换一个吧
点赞 评论 收藏
分享
10-10 17:46
门头沟学院 Java
廖依然:所以能分我一个offer吗?求求了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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