题解 | #密码强度等级#

密码强度等级

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

#那些直接用isdig isupper islower判断的更推荐
import re
a=input()
s=0

dig=False
ab=False
AB=False
fuhao=False

#判断长度
if len(a)<=4:
    s+=5
elif len(a)>=5 and len(a)<=7:
    s+=10
elif len(a)>=8:
    s+=25
# print(s)
#判断是否有字母
if re.search('[a-z]',a):
    ab=True
    s+=10
if re.search('[A-Z]',a):
    AB=True
    s+=10
# print(s)

#判断数字
if re.search('[0-9]',a):
    dig=True
    if len(re.findall('[0-9]',a))==1:
        s+=10
    else:
        s+=20
# print(s)

#判断符号
if re.search('[^a-zA-Z0-9]',a):
    fuhao=True
    if len(re.findall('[^a-zA-Z0-9]',a))==1:
        s+=10
    elif len(re.findall('[^a-zA-Z0-9]',a))>1:
        s+=25

if dig and ab and not fuhao and not AB:
    s+=2
elif dig and AB and not fuhao and not ab:
    s+=2
elif dig and ab and fuhao and not AB:
    s+=3
elif dig and AB and fuhao and not ab:
    s+=3
elif dig and ab and fuhao and  AB:
    s+=5

# print(s)
if s>=90:
    print("VERY_SECURE")
if s>=80 and s<90:
    print("SECURE")
if s>=70 and s<80:
    print("VERY_STRONG")
if s>=60 and s<70:
    print("STRONG")
if s>=50 and s<60:
    print("AVERAGE")
if s>=25 and s<50:
    print("WEAK")
if s>=0 and s<25:
    print("VERY_WEAK")

全部评论

相关推荐

01-14 12:34
门头沟学院 C++
牛马人的牛马人生:太暖心了啊 配环境是真烦
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
2025-12-04 21:05
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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