题解 | #密码强度等级#
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
def length(s): lenth = len(s) if lenth <= 4: return 5 elif 5 <= lenth <= 7: return 10 else: return 25 def alp(s): global char_l char_l = 0 global char_u char_u = 0 global num num = 0 global sign sign = 0 for c in s: if c.isupper() == True: char_u += 1 elif c.islower() == True: char_l += 1 elif c.isdigit() == True: num += 1 elif c in "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~": # 将"和\转义 sign += 1 if (char_l + char_u) == 0: return 0 elif char_l == 0 and char_u != 0: return 10 elif char_u == 0 and char_l != 0: return 10 elif char_u * char_l > 0: return 20 def digit(s): if num == 0: return 0 elif num == 1: return 10 elif num > 1: return 20 def sig(s): if sign == 0: return 0 elif sign == 1: return 10 elif sign > 1: return 25 def reward(s): if sign == 0 and num != 0 and char_l + char_u != 0: return 2 elif sign != 0 and num != 0 and char_l * char_u != 0: return 5 elif sign != 0 and num != 0 and char_l + char_u != 0: return 3 else: return 0 def final_mark(s): countscore = int(length(s))+int(alp(s))+int(digit(s))+int(sig(s))+int(reward(s)) if countscore>=90: print("VERY_SECURE") if 80<=countscore<90: print("SECURE") if 70<=countscore<80: print("VERY_STRONG") if 60<=countscore<70: print("STRONG") if 50<=countscore<60: print("AVERAGE") if 25<=countscore<50: print("WEAK") if 0<=countscore<25: print("VERY_WEAK") s = input() final_mark(s)