I want to create a program wich gives me all possible combination to make a certain number.
So, lets say i want all possible ways to make 15 with 3 digits with the numbers 1 till 9 (9 included), this is simple:
# python2 result =  for a in range(1,10): for b in range(1,10): for c in range(1,10): x = [a,b,c] x.sort() if a + b + c == 15: if len(set(x)) == 3: if x not in result: result.append(x) print result
with 4 or 5 digits, its also easy, you just add one or two more loops. The part where i get stuck is if i let the user choice how many digits he wants (3, 4 or 5 digits), because then, i can't hard code the loop.
Can somebody help me in the right direction?