题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
while True: try: s = input() sc = 0 # 密码长度 if len(s) <= 4: sc = sc + 5 elif len(s) <= 7: sc = sc + 10 else: sc = sc + 25 # 字母 isu = 0 isl = 0 for i in s: if i.isupper(): isu = 1 break for i in s: if i.islower(): isl = 1 break sc = sc + 10 * (isu + isl) # 数字 shu = '0123456789' count1 = 0 for i in s: if i in shu: count1 = count1 + 1 if count1 == 1: sc = sc + 10 elif count1 > 1: sc = sc + 20 else: sc = sc # 符号 fh = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' count2 = 0 for i in s: if i in fh: count2 = count2 + 1 if count2 == 1: sc = sc + 10 elif count2 > 1: sc = sc + 25 else: sc = sc # 奖励 if isu + isl == 2 and count1 >= 1 and count2 >= 1: sc = sc + 5 elif isu + isl > 1 and count1 >= 1 and count2 >= 1: sc = sc + 3 elif isu + isl > 1 and count1 >= 1: sc = sc + 2 if sc >= 90: print("VERY_SECURE") elif sc >= 80: print("SECURE") elif sc >= 70: print("VERY_STRONG") elif sc >= 60: print("STRONG") elif sc >= 50: print("AVERAGE") elif sc >= 25: print("WEAK") elif sc >= 0: print("VERY_WEAK") except: break