我需要使用以下代码在itertools.product
中重复一次:
minLength=InputInt(" Please Enter the Min Length of Your Word : ")
maxLength=InputInt(" Please Enter the Max Length of Your Word : ")
characters=input(" Please Enter the Character of Your Word : ")
res = itertools.product(characters, repeat=range(minLength,maxLength))
for i in res:
print(' Password Created : ',''.join(i), end='\r',flush=True)
但是当我使用此代码repeat=range(minLength,maxLength)
时,会显示此错误:
res = itertools.product(字符,重复=范围(minLength,maxLength)) TypeError:“范围”对象不能解释为整数
出什么问题?我该如何解决这个问题?
答案 0 :(得分:2)
您不能这样做,请使用:
res = [x for i in range(minLength,maxLength) for x in itertools.product(characters, repeat=i)]