题解 | #密码强度等级#

密码强度等级

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

# 要求真多
n = input()
score = 0
# 密码长度
if len(n) <= 4:
    score += 5
elif len(n) <= 7 and len(n) > 4:
    score += 10
elif len(n) >= 8:
    score += 25

# 字母
up, low = 0, 0
for i in n:
    if i.isupper():
        up += 1
    elif i.islower():
        low += 1

if up + low != 0:
    if up and low != 0:
        score += 20
    else:
        score += 10

# 数字
num = 0
for x in n:
  if x.isdigit():
    num += 1

if num == 1:
    score += 10
elif num > 1:
    score += 20

# 符号
fh = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
fuhao = 0
for i in n:
    if i in fh:
        fuhao += 1
if fuhao == 1:
    score += 10
elif fuhao > 1:
    score += 25

# 奖励
if up and low and num and fuhao != 0:
    score += 5
elif (up == 0 and low != 0 or low == 0 and up != 0) and num and fuhao != 0:
    score += 2
elif up or low + num != 0:
    score += 2

# 评分
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')
elif score >= 0:
    print('VERY_WEAK')

全部评论
符号好像可以用i.isascii()来判断
点赞 回复 分享
发布于 2023-07-05 08:51 湖北

相关推荐

评论
点赞
收藏
分享

创作者周榜

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