【Python】有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是 多少?

python中for循环的使用

numberList=[1,2,3,4]
complexList=[]
def permutationNum():
    for i in numberList:
        for j in numberList:
                for k in numberList:
                    if i!=j and k != j and i!=k:
                        complexList.append(str(i)+str(j)+str(k))
    print("共有{}种组合,分别为{}".format(len(complexList),complexList))

permutationNum()

在这里插入图片描述

发布了51 篇原创文章 · 获赞 229 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/famur/article/details/105197445