题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
while 1:
try:
# 密码长度
score = 0
s = input()
if len(s) <= 4:
score += 5
elif len(s) >= 8:
score += 25
else:
score += 10
# 密码内容
low = 0
upp = 0
dig = 0
sym = 0
for i in s:
if i.islower():
low = 1
elif i.isupper():
upp = 1
elif i.isdigit():
dig += 1
elif i.isascii():
sym += 1
if dig > 1:
dig = 2
if sym > 1:
sym = 2.5
score += int(10*(low + upp + dig + sym))
# 强度奖励
ben = 0
if low != 0 or upp != 0:
if dig != 0:
ben = 2
if sym != 0:
ben = 3
if low != 0 and upp !=0:
ben = 5
score += ben
# 得分判定
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')
else:
print('VERY_WEAK')
except:
break