+ 3
pin code
can any body help me to write code using recursive function to print pin code. by giving the program pin length and the max number it will give you pin code. for example: when we give it length is 3 and the max number is 2. It will print: 111 112 121 122 211 212 221 222 thanks in advance
1 Respuesta
0
Python 3 has a function to do this actually.
from itertools import product
If we wanted to print out exactly what you wrote:
print(list(product([1,2], repeat=3)))
The list contains the numbers you wish to make permutations from, so the digits you want to make combinations from. The repeat flag specifies the length of the permutation. In this case, the length of your pin.
I'll leave it up to you how you want to set the values and all that.