题解 | #密码强度等级#

密码强度等级

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

def count_char(x):
    count = 0
    for i in range(len(x)):
        if x[i].isalpha():
            count += 1
    return count

def count_digits(x):
    count = 0
    for i in range(len(x)):
        if x[i].isdigit():
            count += 1
    return count

def count_fuhao(x):
    fsm = "!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"
    count = 0
    for i in range(len(x)):
        if x[i] in fsm:
            count += 1
    return count

def func(x):
    score = 0
    score += 5 if len(x) <= 4 else 10 if 5 <= len(x) <= 7 else 25
    score += 0 if count_char(x) <= 0 else 10 if (x.islower() or x.isupper()) else 20
    score += 0 if count_digits(x) <= 0 else 10 if count_digits(x) == 1 else 20
    score += 0 if count_fuhao(x) <= 0 else 10 if count_fuhao(x) == 1 else 25
    if count_char(x) > 0 and not x.islower() and count_digits(x) > 0 and count_fuhao(x) > 0:
        score += 5
    elif count_char(x) > 0 and count_digits(x) > 0 and count_fuhao(x) > 0:
        score += 3
    elif count_char(x) > 0 and count_digits(x) > 0:
        score += 2
    else:
        score += 0
    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')

while True:
    try:
        a = input()
        func(a)
    except:
        break

全部评论

相关推荐

11-01 08:48
门头沟学院 C++
伤心的候选人在吵架:佬你不要的,能不能拿户口本证明过户给我。。球球了
点赞 评论 收藏
分享
10-28 15:45
门头沟学院 C++
西南山:海康威视之前不是大规模裁员吗
点赞 评论 收藏
分享
吃辣椒还买票:没有一个公司不加班的,不加班的公司哪有收益给你开工资啊
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务