0

This is my code for getting a 3 digit combination.

a = input("Enter first number: ")
b = input("Enter second number: ")
c = input("Enter third number: ")
d = []

d.append(a)
d.append(b)
d.append(c)


for i in range(0, 4):
    for j in range(0, 4):
        for k in range(0, 4):
            if(i !=j & j!=k & k!=i):
                
                 for count, i in enumerate(range(4),1):
                    print(i,j,k)

Input:

1,2,3

and Output:

0 1 2
1 1 2
2 1 2
3 1 2
0 2 0
1 2 0
2 2 0
3 2 0 & more....

My question is how can I get the count of how many combinations I have got?

Thank you so much for your attention and participation.

2
  • Perhaps just count the number of times print() is called. Or put the numbers in a list and find the length of the list at the end. (btw what is the point of your first 7 lines?) Commented May 22, 2022 at 20:15
  • I don't see that d is being used. Commented May 22, 2022 at 20:17

1 Answer 1

1

Outside of your loop, create an integer variable and set it equal to 0. Where you print out the combinations (within the loop), add 1 to this integer variable. Finally at the end of your program outside the loop, print the value of the counter variable.

For example:

counter = 0

for i in range(0, 4):
    for j in range(0, 4):
        for k in range(0, 4):
            if (i != j & j != k & k != i):

                for count, i in enumerate(range(4), 1):
                    print(i, j, k)
                    counter += 1

print(counter)
Sign up to request clarification or add additional context in comments.

2 Comments

I have a question If I decide to change the range to (0, 9). should I change enumerate(range(4), 1) > enumerate(range(9), 1)?
@AbdulAhad most likely yes - but I do not have the full code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.