题目描述
用于密码的英文字符被分为四种:(1)字母(2)数字(3)英文标点符号(4)其他所有英文字符。
其中,标点符号包括: ?!.,'";:`_-()[]/*
现在用户输入一行字符作为密码,程序判断其强度。规则为:(1)密码长度小于8为弱密码,判定为”weak“;(2)密码长度大于等于8,且只包含一种字符也为弱密码;(3)密码长度大于等于8,且包含两种字符为中等密码,判定为”medium“;(3)密码长度大于等于8,且包含三种字符为强密码,判定为”good“;(4)密码长度大于等于8,且包含四种字符为极强密码,判定为”excellent“
例如密码:”abc123“为弱密码,输出"weak";
密码“1234567890“为弱密码,输出"weak";
密码“123abdef”为中等密码,输出"medium";
密码“123()abdef”为强密码,输出"good";
密码“123()abd@”为极强密码,输出"excellent";
提示
输入输出格式
输入格式
一行英文字符串,长度小于128,作为要判定的密码
输出格式
密码的强度等级
输入输出样例
输入
zhang@163.com
输出
excellent
c含有引号,会引发错误,可加转义符规避。或者加号拼接。
import string
s = input()
a = string.digits
b = string.ascii_letters
c = "?!.,'\";:`_-()[]/*"
count1, count2, count3, count4 = 0, 0, 0, 0
if len(s) < 8:
print("weak")
else:
for i in s:
if i in a:
count1 = 1
elif i in b:
count2 = 1
elif i in c:
count3 = 1
else:
count4 = 1
count = count1 + count2 + count3 + count4
if count <= 1:
print("weak")
elif count == 2:
print("medium")
elif count == 3:
print("good")
elif count == 4:
print("excellent")