|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
校验密码是否合法:编写程序提示用户输入一个密码,要求长度在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。
是哪儿出错了啊
password=input()
numlower=0
numisupper=0
numdigit=0
if 5<=len(password)<=10:
for p in password:
if p.islower():
numlower+=1
elif p.isupper():
numisupper+=1
elif p.isdigit():
numdigit+=1
if numlower>0 and numdigit> and numisupper>0:
print('Password input success')
else:
print('Password must include uppercase,lowercase and digit')
else:
print('The length of password must in range of 5-10')
代码的逻辑和语法基本上没有问题,重点检查代码的缩进,每级4个空格,必须严格遵守。
- password = input()
- numlower = 0
- numisupper = 0
- numdigit = 0
- if 5 <= len(password) <= 10 :
- for p in password:
- if p . islower():
- numlower += 1
- elif p . isupper():
- numisupper += 1
- elif p . isdigit():
- numdigit += 1
- if numlower > 0 and numdigit > 0 and numisupper > 0 :
- print('Password input success')
- else:
- print('Password must include uppercase,lowercase and digit')
- else:
- print('The length of password must in range of 5-10')
复制代码
|
|