How to use four numbers to achieve non-repetitive three-digit numbers with python

How to use four numbers to achieve non-repetitive three-digit numbers with python

Mainly use three loops, three nested loops to combine three numbers, if it is three different numbers, it can be printed out, and at the same time use a sum to count their number, and finally put print on the right to print out total.

sum=0
for i in range (1,5):
    for j in range(1,5):
        for k in range(1,5):
            if (i!=k)and (i!=j)and(j!=k):
                print(i,j,k)
                sum+=1
print(sum)

Below are the three-digit results and total

1 2 3
1 2 4
1 3 2
1 3 4
1 4 2
1 4 3
2 1 3
2 1 4
2 3 1
2 3 4
2 4 1
2 4 3
3 1 2
3 1 4
3 2 1
3 2 4
3 4 1
3 4 2
4 1 2
4 1 3
4 2 1
4 2 3
4 3 1
4 3 2
24

Guess you like

Origin blog.csdn.net/weixin_47567401/article/details/112793919