我正在制作一个函数,它使用 while True 循环来要求用户输入通过条件的密码;长度最少为 8-15 个字符,并且至少包含一个整数。我对如何正确检查整数的输入感到困惑。
我的程序:
def enterNewPassword():
while True:
pw = input('Please enter a password :')
for i in pw:
if type(i) == int:
if len(pw) >= 8 and len(pw) <= 15:
break
if int not in pw:
print('Password must contain at least one integer.')
if len(pw) < 8 or len(pw) > 15:
print('Password must be 8 and no more than 15 characters in length.')
return pw
Try:
if not any(c.isdigit() for c in pw)
代替
if int not in pw:
print('Password must contain at least one integer.')
int
是一个类型对象,您想要检查字符 0-9 是否存在。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)