gpt4 book ai didi

Python - 检查字符串是否包含数字

转载 作者:行者123 更新时间:2023-11-28 22:40:53 24 4
gpt4 key购买 nike

<分区>

我正在制作一个函数,它使用 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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com