python-校验密码小练习

#校验密码是否合法的小练习
#1、密码长度5到10位;
#2、密码里面必须包含,大写字母,小写字母,数字
#3、最多输入5次

写程序过程中遇到了两个问题,第二个循环里的P是把password的值循环传到p里面去;例如密码输入'123abcABC';是循环从1开始依次取字符串里的值;第二个问题:
p.isupper写错误,导致numissupper值一直为0;所以一直走不到密码校验通过


for i in range(10):
password=input('请输入你的密码:').strip()
if len(password)>4 and len(password)<10:
numlower = 0
numisupper = 0
numdigit = 0
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('密码校验通过')
break
else:
print('密码不符合要求')
else:
print('长度不符合要求')

# for i in range(10):
# password = input('输入密码:')
# #print(password.islower()) #仅小写字母=T,不包含就为假;数字+小写字母=T 小写字母+大写字母=False
# #print(password.isupper()) # 仅大写字母=T,不包含就为假;数字+大写字母=T 小写字母+大写字母=False
# #print(password.isdigit()) #仅有数字组成

猜你喜欢

转载自www.cnblogs.com/ruijie/p/10048921.html