简体   繁体   中英

How to get the count of lines in a output of a python script

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM