题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
password = input()
score, num, up_char, low_char, other = 0, 0, 0, 0, 0
if len(password) <= 4:
score += 5
elif len(password) <= 7:
score += 10
else:
score += 25
for char in password:
if char.isdigit():
num += 1
elif char.isalpha():
if char.isupper():
up_char += 1
else:
low_char += 1
else:
other += 1
if up_char or low_char:
score += 10
if up_char and low_char:
score += 10
if num == 1:
score += 10
elif num > 1:
score += 20
if other == 1:
score += 10
elif other > 1:
score += 25
if num and (up_char or low_char):
score += 2
if other:
score += 1
if up_char and low_char:
score += 2
def grade(s):
if s >= 90:
return "VERY_SECURE"
elif s >= 80:
return "SECURE"
elif s >= 70:
return "VERY_STRONG"
elif s >= 60:
return "STRONG"
elif s >= 50:
return "AVERAGE"
elif s >= 25:
return "WEAK"
else:
return "VERY_WEAK"
print(grade(score))