【发布时间】:2015-10-19 01:32:50
【问题描述】:
我正在制作一个使用 while True 循环来要求用户输入通过条件的密码的函数; min8-15max 个字符的长度,并且至少包含一个整数。我对如何正确检查整数的输入感到困惑。
我的程序:
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
【问题讨论】: