题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
def lenth(s): # 长度 if len(s) <= 4: return 5 elif 4 < len(s) < 8: return 10 elif len(s) >= 8: return 25 return 0 # 字母 def zimu(s): a, b = 0, 0 for i in s: if i.isalpha(): if i in 'qwertyuiopasdfghjklzxcvbnm': a += 1 if i in 'QWERTYUIOPASDFGHJKLZXCVBNM': b += 1 if a > 0 and b > 0: return 20 if (a > 0 and b == 0) or (a == 0 and b > 0): return 10 return 0 # 数字 def shuzi(s): shu = 0 for i in s: if i in '1234567890': shu += 1 if shu == 1: return 10 if shu > 1: return 20 return 0 # 符号 def fuhao(s): sum = 0 fh = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' for i in s: if i in fh: sum += 1 if sum == 1: return 10 elif sum > 1: return 25 return 0 while True: try: s = input() a,b,c,d = lenth(s),zimu(s),shuzi(s),fuhao(s) anw = a + b + c + d if b != 0 and c != 0 and d == 0: anw += 2 elif b < 20 and c != 0 and d != 0: anw += 3 elif b == 20 and c != 0 and d != 0: anw += 5 if anw >= 90: print('VERY_SECURE') elif 80 <= anw < 90: print('SECURE') elif 70 <= anw < 80: print('VERY_STRONG') elif 60 <= anw < 70: print('STRONG') elif 50 <= anw < 60: print('AVERAGE') elif 25 <= anw < 50: print('WEAK') else: print('VERY_WEAK') except: break
#华为od#