题解 | #密码强度等级#

密码强度等级

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

import re
def length(a) ->int:
    if len(a)<=4: return 5
    elif len(a)>=5 and len(a) <= 7: return 10
    else: return 25
def word(a) ->int:
    word_count = len(re.findall('[A-Za-z]',a))
    upper_word = len(re.findall('[A-Z]',a))
    lower_word = len(re.findall('[a-z]',a))
    if word_count==0: return 0
    elif upper_word==0 and lower_word!=0 or upper_word!=0 and lower_word==0: return 10
    elif upper_word!=0 and lower_word!=0: return 20
def nums(a) ->int:
    nums_count = len(re.findall('[0-9]',a))
    if nums_count==0: return 0
    elif nums_count==1: return 10
    elif nums_count > 1: return 20
def symbol(a)-> int:
    symbol = len(re.findall(r"[!\"#$%&'()*+,-./:;<=>?@\[\\\]^_`{\|}~]",a))
    if symbol==0: return 0
    elif symbol==1: return 10
    elif symbol>1: return 25
def reward(a):
    if nums(a)!=0 and word(a)!=0: 
        if symbol(a)!=0:
            if word(a)==20:
                return 5
            return 3
        return 2
    return 0
def output(result):
    if result >=90: return 'VERY_SECURE'
    if result >=80: return 'SECURE'
    if result >=70: return 'VERY_STRONG'
    if result >=60: return 'STRONG'
    if result >=50: return 'AVERAGE'
    if result >=25: return 'WEAK'
    if result >=0: return 'VERY_WEAK'
if __name__=='__main__':
    a = input()
    result = length(a)+word(a)+nums(a)+symbol(a)+reward(a)
    # print(result)
    print(output(result))

全部评论

相关推荐

待现的未见之事:起码第一句要把自己的优势说出来吧。比如什么xx本27届学生,随时到岗....
点赞 评论 收藏
分享
求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务