Python题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import sys
while True:
try:
s = input()
l, w, d, c = 0, 0, 0, 0
if len(s) <= 4:
l = 5
elif 5 <= len(s) <= 7:
l = 10
elif len(s) >= 8:
l = 25
a = [0] * 2
num = 0
ch = 0
for i in s:
if i.isupper():
a[0] += 1
elif i.islower():
a[1] += 1
elif i.isdigit():
num += 1
else:
ch += 1
if (num + ch) == len(s):
w = 0
elif a[0] + (num + ch) == len(s) or a[1] + (num + ch) == len(s):
w = 10
elif a[0] != 0 and a[1] != 0:
w = 20
if num == 0:
d = 0
elif num == 1:
d = 10
elif num > 1:
d = 20
if ch == 0:
c = 0
elif ch == 1:
c = 10
elif ch > 1:
c = 25
j = 0
if (a[0] != 0 and num != 0) or (a[1] != 0 and num != 0):
j = 2
if (a[0] != 0 and num != 0 and ch != 0) or (a[1] != 0 and num != 0 and ch != 0):
j = 3
if a[0] != 0 and a[1] != 0 and num != 0 and ch != 0:
j = 5
sum_score = l + w + d + c + j
if sum_score >= 90:
print('VERY_SECURE')
elif 90 > sum_score >= 80:
print('SECURE')
elif 80 > sum_score >= 70:
print('VERY_STRONG')
elif 70 > sum_score >= 60:
print('STRONG')
elif 60 > sum_score >= 50:
print('AVERAGE')
elif 50 > sum_score >= 25:
print('WEAK')
else:
print('VERY_WEAK')
except:
break
