题解 | #密码强度等级#

密码强度等级

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

s = input()
score = 0
count_notalpha = 0
count_notdigit = 0
count_lowup = 0
if len(s) >= 8:
    score += 25
elif len(s) >= 5:
    score += 10
else:
    score += 5
for i in s:
    if i.isalpha() == False:
        count_notalpha += 1
if count_notalpha == len(s):
    score += 0
elif s.islower() or s.isupper():
    score += 10
else:
    score += 20
    count_lowup = 1#用于记录大小写混合的状态,以便后面判断。
for j in s:
    if j.isdigit() == False:
        count_notdigit += 1
if count_notdigit == len(s):
    score += 0
elif len(s) - count_notdigit == 1:
    score += 10
else:
    score += 20
if count_notalpha + count_notdigit == len(s):
    score += 0
elif count_notalpha + count_notdigit - len(s) == 1:
    score += 10
else:
    score += 25
if count_lowup == 1 and len(s) - count_notdigit >= 1 and count_notalpha + count_notdigit - len(s) >= 1:
    score += 5
elif len(s) - count_notalpha >= 1 and len(s) - count_notdigit >= 1 and count_notalpha + count_notdigit - len(s) >= 1:
    score += 3
elif len(s) - count_notalpha >= 1 and len(s) - count_notdigit >= 1:
    score += 2
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")

全部评论

相关推荐

04-15 23:42
中山大学 Java
ResourceUtilization:过几天楼主就会捧着一堆offer来问牛友们该怎么选辣
点赞 评论 收藏
分享
05-08 14:40
广东白云学院
各位大佬方狠狠批评吧
凌offer:投私企,政治面貌不是党员或者预备党员就不要写了,什么族感觉也没啥要写的必要
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务