赞
踩
本题根据题目要求一步步写即可
input_str = input() score = 0 if len(input_str) < 5: score += 5 elif len(input_str) >= 5 and len(input_str) <= 7: score += 10 else: score += 25 number = 0 up_char = 0 low_char = 0 other = 0 for i in input_str: if i.isdigit(): number += 1 elif i.isupper(): up_char += 1 elif i.islower(): low_char += 1 else: other += 1 if up_char == 0 or low_char == 0: score += 10 else: score += 20 if number == 1: score += 10 elif number > 1: score += 20 if other == 1: score += 10 elif other > 1: score += 25 if number > 0 and up_char > 0 and low_char > 0 and other > 0: score += 5 elif number > 0 and up_char + low_char > 0 and other > 0: score += 3 elif number > 0 and up_char + low_char > 0: score += 2 if score >= 0 and score < 25: print("VERY_WEAK") elif score >= 25 and score < 50: print("WEAK") elif score >= 50 and score < 60: print("AVERAGE") elif score >= 60 and score < 70: print("STRONG") elif score >= 70 and score < 80: print("VERY_STRONG") elif score >= 80 and score < 90: print("SECURE") elif score >= 90: print("VERY_SECURE")
时间复杂度:
O
(
n
)
O(n)
O(n)
空间复杂度:
O
(
1
)
O(1)
O(1)
# 整理上述写法 def score_tool(input_str): score = 0 number = 0 up_char = 0 low_char = 0 other = 0 if len(input_str) < 5: score += 5 elif len(input_str) >= 5 and len(input_str) <= 7: score += 10 else: score += 25 for i in input_str: if i.isdigit(): number += 1 elif i.isupper(): up_char += 1 elif i.islower(): low_char += 1 else: other += 1 if up_char == 0 or low_char == 0: score += 10 else: score += 20 if number == 1: score += 10 elif number > 1: score += 20 if other == 1: score += 10 elif other > 1: score += 25 if number > 0 and up_char > 0 and low_char > 0 and other > 0: score += 5 elif number > 0 and up_char + low_char > 0 and other > 0: score += 3 elif number > 0 and up_char + low_char > 0: score += 2 return score def level(score): if score >= 0 and score < 25: return "VERY_WEAK" elif score >= 25 and score < 50: return "WEAK" elif score >= 50 and score < 60: return "AVERAGE" elif score >= 60 and score < 70: return "STRONG" elif score >= 70 and score < 80: return "VERY_STRONG" elif score >= 80 and score < 90: return "SECURE" elif score >= 90: return "VERY_SECURE" input_str = input() score = score_tool(input_str) print(level(score))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。