有0,1,2,3,4五个数,能组成多少个互不相同且不重复的三个组合,并打印出每个组合
A=0
for i in range(5):
for j in range(5):
for k in range(5):
if ((i!=j)and(j!=k)and(k!=i)):
print(i,j,k)
A+=1
print(A)
结果输出:
0 1 2
0 1 3
0 1 4
0 2 1
0 2 3
0 2 4
0 3 1
0 3 2
0 3 4
0 4 1
0 4 2
0 4 3
1 0 2
1 0 3
1 0 4
1 2 0
1 2 3
1 2 4
1 3 0
1 3 2
1 3 4
1 4 0
1 4 2
1 4 3
2 0 1
2 0 3
2 0 4
2 1 0
2 1 3
2 1 4
2 3 0
2 3 1
2 3 4
2 4 0
2 4 1
2 4 3
3 0 1
3 0 2
3 0 4
3 1 0
3 1 2
3 1 4
3 2 0
3 2 1
3 2 4
3 4 0
3 4 1
3 4 2
4 0 1
4 0 2
4 0 3
4 1 0
4 1 2
4 1 3
4 2 0
4 2 1
4 2 3
4 3 0
4 3 1
4 3 2
60
Process finished with exit code 0