题解 | #密码强度等级#

密码强度等级

http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

难不难,就是要求比较多,用函数分开来写就行了

``` python []
#密码长度得分计算
def lenscore(x):
    if 0<len(x)<=4:
        return 5
    elif 5<=len(x)<=7:
        return 10
    elif len(x)>=8:
        return 25
    else:
        return 0
    
#字母大小写得分计算
def zimuscore(x):
    x=str(x)
    a=0#计算小写个数
    b=0#计算大写个数
    for i in x:
        if i.islower():#计算小写
            a+=1
        if i.isupper():#计算大写
            b+=1
            
    if (a!=0 and b==0) or (b!=0 and a==0):#全是小写或者全是大写
        return 10
    if a!=0 and b!=0:#大小写混合
        return 20
    else:
        return 0
    
#数字得分计算:
def digtscore(x):
    x=str(x)
    a=0#计算数字个数
    for i in x:
        if i.isdigit():
            a+=1
    
    if a==1:
        return 10
    if a>1:
        return 20
    else:
        return 0
    
#符号得分计算
def fhscore(x):
    x=str(x)
    a=0#计算符号个数
    fsm="!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"
    for i in x:
        if i in fsm:
            a+=1
    
    if a==1:
        return 10
    if a>1:
        return 25
    else:
        return 0
    
#奖励得分计算
def jlscore(x):
    x=str(x)
    a=0#计算小写个数
    b=0#计算大写个数
    for i in x:
        if i.islower():#计算小写
            a+=1
        if i.isupper():#计算大写
            b+=1
            
    if ((a!=0 and b==0) or (b!=0 and a==0)) and digtscore(x)!=0:#字母加数字
        return 2
    if ((a!=0 and b==0) or (b!=0 and a==0)) and digtscore(x)!=0 and fhscore(x):#字母加数字加符号
        return 3
    if (a!=0 and b!=0) and digtscore(x)!=0 and fhscore(x):#大小写字母加数字加符号
        return 5
    else:
        return 0
    
while True:
    try:
        a=str(input())
        countscore=lenscore(a)+zimuscore(a)+digtscore(a)+fhscore(a)+jlscore(a)
        #print(countscore)
        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")
            
    except:
        break
        
        
全部评论
73行判断的是字母加数字,有可能是大小写字母吧,应该是if (a!=0 or b!=0 ) and digtscore(x)!=0:#字母加数字吧
1 回复 分享
发布于 2022-06-22 00:26
73和75应该换个位置把我感觉,奖励3分的情况和奖励两分的应该优先奖励3分吧
点赞 回复 分享
发布于 2022-08-21 17:23 广东
y = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' 转义好细节
点赞 回复 分享
发布于 2022-08-04 08:08
奖励的分的计算是不是可以调用字母函数?
点赞 回复 分享
发布于 2022-04-15 23:35

相关推荐

点赞 评论 收藏
分享
评论
12
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务