题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
s = input() score = 0 count_notalpha = 0 count_notdigit = 0 count_lowup = 0 if len(s) >= 8: score += 25 elif len(s) >= 5: score += 10 else: score += 5 for i in s: if i.isalpha() == False: count_notalpha += 1 if count_notalpha == len(s): score += 0 elif s.islower() or s.isupper(): score += 10 else: score += 20 count_lowup = 1#用于记录大小写混合的状态,以便后面判断。 for j in s: if j.isdigit() == False: count_notdigit += 1 if count_notdigit == len(s): score += 0 elif len(s) - count_notdigit == 1: score += 10 else: score += 20 if count_notalpha + count_notdigit == len(s): score += 0 elif count_notalpha + count_notdigit - len(s) == 1: score += 10 else: score += 25 if count_lowup == 1 and len(s) - count_notdigit >= 1 and count_notalpha + count_notdigit - len(s) >= 1: score += 5 elif len(s) - count_notalpha >= 1 and len(s) - count_notdigit >= 1 and count_notalpha + count_notdigit - len(s) >= 1: score += 3 elif len(s) - count_notalpha >= 1 and len(s) - count_notdigit >= 1: score += 2 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")