校验密码是否合法:编写程序提示用户输入一个密码,要求长度在5-10位,密码里必须包含大写字母、小写字母和数字。根据用户输入会返回相应提示信息:如果密码长度不合法,返回“The length of password must in range of 5-10”;如果密码内容不合法,返回"Password must include uppercase,lowercase and digit",否则返回“Password input success”。提示:可利用S.isdisjoint(T)方法,如果集合S与T没有相同元素,返回True。
输入格式:
一个字符串
输出格式:
一个字符串
输入样例:
asdQEWr123
输出样例:
Password input success
inp=input('input a password, length of 5-10:')
import string
if len(inp)<5 or len(inp)>10:
print('The length of password must in range of 5-10')
elif set(inp).isdisjoint(set(string.ascii_lowercase)) or set(inp).isdisjoint(set(string.ascii_uppercase)) or set(inp).isdisjoint(set(string.digits)):
print("Password must include uppercase,lowercase and digit")
else:
print('pssword input success')
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m
inp=input()
import string
if len(inp)<5 or len(inp)>10:
print('The length of password must in range of 5-10')
elif set(inp).isdisjoint(set(string.ascii_lowercase)) or set(inp).isdisjoint(set(string.ascii_uppercase)) or set(inp).isdisjoint(set(string.digits)):
print("Password must include uppercase,lowercase and digit")
else:
print('Password input success')