题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
###就当是锻炼耐心了,稍微注意的点就是判断各种类型字符同时存在时逻辑不能乱
def long(x:str):
if len(x) <= 4:
return 5
elif 5 <= len(x) <= 7:
return 10
elif len(x) >= 8:
return 25
def alpha(x:str):
a,b=0,0
for i in x:
if i.islower():
a = 1
elif i.isupper():
b = 1
if a+b == 2:
return 20
elif a+b == 1:
return 10
elif a+b == 0:
return 0
def num(x:str):
a = 0
for i in x:
if i.isnumeric():
a+=1
if a == 0:
return 0
elif a == 1:
return 10
elif a > 1:
return 20
def fuhao(x:str):
import string
teshu = string.punctuation
a = 0
for i in x:
if i in teshu:
a+=1
if a == 0:
return 0
elif a == 1:
return 10
elif a > 1:
return 25
def jiangli(x:str):
import string
teshu = string.punctuation
a,b,c,d=0,0,0,0
for i in x:
if i.isnumeric():
a=1
elif i in teshu:
b=1
elif i.isupper():
c=1
elif i.islower():
d=1
if a+b+c+d ==4:
return 5
elif (a+b+c)==3 or (a+b+d)==3:
return 3
elif (a+c) ==2 or (a+d) ==2:
return 2
else:
return 0
while True:
try:
s = str(input())
if 1 <= len(s) <= 300:
score=long(s)+alpha(s)+num(s)+fuhao(s)+jiangli(s)
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')
else:
print('密码越界,请重新输入')
except:
break

查看11道真题和解析