gpt4 book ai didi

python - 传递参数和范围时出现问题,如何解决这个问题?

转载 作者:行者123 更新时间:2023-12-01 01:06:23 25 4
gpt4 key购买 nike

我正在制作一个密码生成器和强度检查器(我是编码新手),我的问题是我无法让一个函数生成密码,调用检查强度的函数,并有强度检查函数返回生成函数。

抱歉,如果这是一个错误的解释,请检查代码以进行澄清。

我尝试过的所有方法都部分有效或根本无效,包括使用全局变量;即使这样我也无法让它正常运行。

import random
allchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!$%^&*()_-=+"
def generatePassword():
generatedPass = ""
while points < 20:
for i in range(random.randint(8, 12)):
generatedPass += random.choice(allchars)
checkFunc(generatedPass)
points = 0

print(generatedPass)


def checkFunc(password):
numberofTriples = 0
consecChars = []
points = 0
allCrit = 0
(Redacted code that just calculates the points of the password)
(Redacted code that just calculates the points of the password)
return points

我希望它随机生成密码,并检查其强度,如果它低于某个点阈值,则生成另一个密码,直到它高于阈值,然后打印它。

最佳答案

您的generatedPassword函数从未设置 points 的值在 while循环,因此它永远不会满足 points < 20 的条件.

您想要更改checkFunc(generatedPass)points = checkFunc(generatedPass) 。这将正确设置点的值,并从循环中中断。

关于python - 传递参数和范围时出现问题,如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55308393/

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