为什么程序陷入死循环了
from random import randintdef passwd():
passwd_length = randint(7, 10)
passwd1 = ''
for i in range(0, passwd_length):
s = randint(33, 126)
passwd1 += chr(s)
return passwd1
def good_password(passwd1):
if len(passwd1) >= 8 and passwd1.isupper() and passwd1.islower() and passwd1.isdigit():
return True
else:
return False
def judgement():
n = 0
while 1:
passwd1 = passwd()
if good_password(passwd1):
n += 1
break
else:
n += 1
return n
def main():
print('Need', judgement(), 'times to create a good password!')
if __name__ == '__main__':
main()
运行始终无结果,是不是卡在while循环了? 本帖最后由 jackz007 于 2021-10-21 21:04 编辑
if len(passwd1) >= 8 and passwd1.isupper() and passwd1.islower() and passwd1.isdigit():
这一句逻辑冲突,就好比一个人,他不可能是男人,同时,也是女人。也许,你应该把其中部分 and 统统改成 or
改成这样试试?
if len(passwd1) >= 8 and (passwd1.isupper() or passwd1.islower() or passwd1.isdigit()):
页:
[1]