题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
var = input() ## 统计数字、大写字母、小写字母、特殊符号存在的次数 def getCountlist(pwd): countNum = 0 countCharLow = 0 countCharUpper = 0 counFh = 0 fh = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" for i in range(0, len(pwd)): tmp = pwd[i:i+1] if tmp.isdecimal(): countNum = countNum + 1 if tmp.islower(): countCharLow = countCharLow + 1 if tmp.isupper(): countCharUpper = countCharUpper + 1 if tmp in fh: counFh = counFh + 1 i = i + 1 return countNum, countCharLow, countCharUpper, counFh res = 0 countNum, countCharLow, countCharUpper, counFh = getCountlist(var) len_var = len(var) ## 判断长度 if len_var <= 4: res = res + 5 if len_var >= 5 and len_var <= 7: res = res + 10 if len_var >= 8: res = res + 25 ## 判断数字个数 if countNum == 1: res = res + 10 if countNum > 1: res = res + 20 ## 判断字母 if (countCharLow >= 1 and countCharUpper == 0) or ( countCharLow == 0 and countCharUpper >= 1 ): res = res + 10 if countCharLow >= 1 and countCharUpper >= 1: res = res + 20 ## 判断特殊符号 if counFh == 1: res = res + 10 if counFh > 1: res = res + 25 ## 判断奖励 if countNum >= 1 and countCharLow >= 1 and countCharUpper >= 1 and counFh >= 1: res = res + 5 elif countNum >= 1 and countCharLow + countCharUpper >= 1 and counFh >= 1: res = res + 3 elif countNum >= 1 and countCharLow + countCharUpper >= 1: res = res + 2 ## 打印处理 if res >=90: print('VERY_SECURE') if res >=80 and res <90: print('SECURE') if res >=70 and res <80: print('VERY_STRONG') if res >=60 and res <70: print('STRONG') if res >=50 and res <60: print('AVERAGE') if res >=25 and res <50: print('WEAK') elif res >=0 and res < 25 : print('VERY_WEAK')