题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
# for line in sys.stdin:
# a = line.split()
# print(int(a[0]) + int(a[1]))
# 长度len 字母isupper islower isalpha
# 数字isdigit 符号!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~
# 奖励reward
# 利用函数的方法解决
# 长度得分
def psw_len(str):
if len(str) >= 8:
return 25
elif len(str) >= 5:
return 10
else:
return 5
# 字母得分
def alpha_score(str):
score_upper,score_lower = 0,0 #初始化数据防止出现加不存在的数据
for i in str:
if i.isupper():
score_upper = 10
break
for i in str:
if i.islower():
score_lower = 10
break
return score_upper + score_lower
# 数字得分
def digit_score(str):
tmp = 0
for i in str:
if i.isnumeric():
tmp = tmp + 10
if tmp == 20:
break
return tmp
# 符号得分
def symbol_score(str):
tmp = 0
for i in str:
bsymbol = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
if i in bsymbol:
tmp = tmp + 10
if tmp == 20:
tmp = 25
break
return tmp
# 奖励的分数
def reward_score(alpha_score, digit_score, symbol_score):
if (
alpha_score == 20 and digit_score != 0 and symbol_score != 0
): # 条件语句中不能用%代替and关键字
return 5
elif alpha_score != 0 and digit_score != 0 and symbol_score != 0:
return 3
elif alpha_score != 0 and digit_score != 0:
return 2
else:
return 0
while True:
try:
str = input()
psw_score = psw_len(str)
alpha_score = int(alpha_score(str))
digit_score = int(digit_score(str))
symbol_score = int(symbol_score(str))
reward_score = int(reward_score(alpha_score, digit_score, symbol_score))
score = int(psw_score + alpha_score + digit_score + symbol_score + reward_score)
# 评分标准
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")
except:
break

汤臣倍健公司氛围 373人发布