题解 | #密码强度等级#

密码强度等级

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

import re
str1 = input()
zm_up, zm_lo, num, fh = [], [], [], []
a, b, c, d = 0, 0, 0, 0
fs = 0
if len(str1) <= 4:
    fs += 5
elif 5 <= len(str1) <= 7:
    fs += 10
elif len(str1) >= 8:
    fs += 25
pat_zm_up = r"[A-Z]"
pat_zm_lo = r"[a-z]"
pat_num = r"[0-9]"
for i in str1:
    if re.match(pat_zm_up, i):
        a = 1
        zm_up.append(i)
    elif re.match(pat_zm_lo, i):
        b = 1
        zm_lo.append(i)
    elif re.match(pat_num, i):
        c = 1
        num.append(i)
    else:
        d = 1
        fh.append(i)
if len(zm_up) != 0 and len(zm_lo) != 0:
    fs += 20
elif len(zm_up) != 0 and len(zm_lo) == 0:
    fs += 10
elif len(zm_up) == 0 and len(zm_lo) != 0:
    fs += 10
if len(num) == 1:
    fs += 10
elif len(num) > 1:
    fs += 20
if len(fh) == 1:
    fs += 10
elif len(fh) > 1:
    fs += 25
if a == 1 and b == 1 and c == 1 and d == 1:
    fs += 5
elif a == 0 and b == 1 and c == 1 and d == 1:
    fs += 3
elif a == 1 and b == 0 and c ==1 and d == 1:
    fs += 3
elif a == 0 and b == 1 and c == 1 and d == 0:
    fs += 2
elif a == 1 and b == 0 and c == 1 and d == 0:
    fs += 2
if fs >= 90:
    print("VERY_SECURE")
elif fs >= 80:
    print("SECURE")
elif fs >= 70:
    print("VERY_STRONG")
elif fs >= 60:
    print("STRONG")
elif fs >= 50:
    print("AVERAGE")
elif fs >= 25:
    print("WEAK")
else:
    print("VERY_WEAK")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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