1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

def fun(num):
    l=[]
    for i in range(1,num):
        for j in range(1,num):
            for k in range(1,num):
                if i != j and j!= k and i != k:
                    print(i,j,k)
                    l.append([i,j,k])
                else:
                    continue
    return l,len(l)

l,length=fun(5)
print(l,length)            
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
[[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

 

posted @ 2020-04-11 19:55  腹肌猿  阅读(1823)  评论(0编辑  收藏  举报