题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
引用正则模块,方便判断
s=input()
def lens(s):
lens_s=len(s)
if lens_s<=4:
score1=5
elif lens_s>=8:
score1=25
else:
score1=10
return score1
def alpha(s):
if not len(re.findall('[a-zA-Z]', s)):
score2=0
elif not len(re.findall('[a-z]', s)) and len(re.findall('[A-Z]', s)):
score2=10
elif not len(re.findall('[A-Z]', s)) and len(re.findall('[a-z]', s)):
score2=10
else:
score2=20
return score2
def num(s):
if not len(re.findall('[\d]', s)):
score3=0
elif len(re.findall('[\d]', s))==1:
score3=10
else:
score3=20
return score3
def fuhao(s):
if not len(re.findall(r'''[!"#$%&'()*+,-./:;<=>?@[\]^_{|}~]''', s)):
score4=0
elif len(re.findall(r'''[!"#$%&'()*+,-./:;<=>?@[\]^_{|}~]''', s))==1:
score4=10
else:
score4=25
return score4
def award(s):
score5=2
if alpha(s)!=0 and num(s)!=0 and fuhao(s)!=0:
score5=3
if alpha(s)==20 and num(s)!=0 and fuhao(s)!=0:
score5=5
return score5
score=lens(s)+alpha(s)+num(s)+fuhao(s)+award(s)
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')

