2

I need to repeat in range with itertools.product with this code:

            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)

but when I use this code repeat=range(minLength,maxLength) it shows me this error:

res = itertools.product(characters, repeat=range(minLength,maxLength)) TypeError: 'range' object cannot be interpreted as an integer

What's the problem? How can I solve this problem?

4
  • Is that code supposed to print 1 password? Or do you want it to print every possible product of those characters with a length in the requested range?
    – PM 2Ring
    Feb 3, 2019 at 7:47
  • @PM2Ring I would like to print this product to any possible product of these characters in length in the requested range Feb 3, 2019 at 7:49
  • So if someone enters 8 for the min & max lengths, and "ABCDEFGHIJ" for the characters, you want the program to print 100 million strings.
    – PM 2Ring
    Feb 3, 2019 at 7:59
  • @PM2Ring yes . it only way Feb 3, 2019 at 8:00

1 Answer 1

3

You can't do that, use:

res = [x for i in range(minLength,maxLength) for x in itertools.product(characters, repeat=i)]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.