首页 > 编程语言 > 详细

python-校验密码小练习

时间:2018-12-01 14:14:01      阅读:134      评论:0      收藏:0      [点我收藏+]
#校验密码是否合法的小练习
#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()) #仅有数字组成

python-校验密码小练习

原文:https://www.cnblogs.com/ruijie/p/10048921.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!