题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
def grade_1(mystr,nowgrade): if len(mystr)<=4: nowgrade+=5 elif len(mystr)>=8: nowgrade+=25 else: nowgrade+=10 return nowgrade def grade_2(mystr,nowgrade): #计数:大写,小写,数字,符号 times=[0,0,0,0] for i in mystr: #数字 if str.isdigit(i): times[2]+=1 #大写字母 elif i.isupper(): times[0]+=1 #小写字母 elif i.islower(): times[1]+=1 #符号 else: times[3]+=1 #字母 if times[0]+times[1]==0: nowgrade+=0 elif times[0]>0 and times[1]>0: nowgrade+=20 else: nowgrade+=10 #数字 if times[2]==1: nowgrade+=10 elif times[2]>1 : nowgrade+=20 else: nowgrade+=0 #符号 if times[3]==1: nowgrade+=10 elif times[3]>1 : nowgrade+=25 else: nowgrade+=0 #奖励 if min(times)>=1: nowgrade+=5 elif max(times[:1])>=1 and min(times[2:])>=1 : nowgrade+=3 elif max(times[:1])>=1 and times[2]>=1: nowgrade+=2 else: nowgrade+=0 return nowgrade def scoretograde(score): if score>= 90: return 'VERY_SECURE' elif score>= 80: return 'SECURE' elif score>= 70: return 'VERY_STRONG' elif score>= 60: return 'STRONG' elif score>= 50: return 'AVERAGE' elif score>= 25: return 'WEAK' elif score>= 0: return 'VERY_WEAK' cipher=input() score=0 score_temp= grade_1(cipher,score) grade=grade_2(cipher,score_temp) print(scoretograde(grade))