马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 MaxFireGun 于 2022-8-29 23:34 编辑 check_mark='~!@#$%^&*()_=-/,.?<>;:[]{}|\\'\
# print(check_mark)
while True:
code = input('Please input ur code here:')
code_len = len(code)
Flag = True
f_check_list=[0,0,0] #[alpha, number, mark]
for i in code:
if i.isalpha():
f_check_list[0] += 1
elif i.isdigit():
f_check_list[1] += 1
elif i in check_mark:
f_check_list[2] += 1
else:
print('Ur code is not standard. Some symbols are not allowed! Please check the code rules as follow: ****')
Flag = False
break
######Check whether there is symbol that is not included in the check_mark######
if Flag == False:
continue
else:
pass
########################################################################
#print(f_check_list)
if code_len <= 8 and ((f_check_list[0] > 0 or f_check_list[1] > 0) and f_check_list[2] == 0):
print('Ur code is in low security level')
break
elif code_len > 8 and int(bool(f_check_list[0])) + int(bool(f_check_list[1])) + int(bool(f_check_list[2])) == 2:
print('Ur code is in medium security level')
break
elif code_len >= 16 and code[0].isalpha() and (f_check_list[0] > 0 and f_check_list[1] > 0 and f_check_list[2] > 0):
print('Ur code is in high security level')
break
else:
print('Ur code is not standard. Please check the code rules as follow: *********')
课后作业说明:
1. 对于满足题目中所给要求的密码,会给出相应的密码安全等级,然后跳出循环。
2.对于不符号不在列表里的,会及时跳出for和while循环,节约计算时间。同时给出'Ur code is not standard. Some symbols are not allowed! Please check the code rules as follow: ****'的提示,并让客户继续输入密码。
2. 对于不满足所有三种要求的密码,会给出'Ur code is not standard, Please check the code rules as follow: balablabla'的提示,并继续让客户输入密码。
3. ‘#’后面的是在测试的过程中用来打印相应的数据,查看程序跑得是否正确,可以忽略。
Beer! Cheers!!
|