Python每天练习——小程序001

                                         Python 练习100题


 2018.8.10

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

def one():
    d=[]
    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):
                    d.append([i,j,k])
    print("总数量:",len(d))
    print(d)
def two():
    '''
    【个人备注】:其实python自带排列组合模块,可以直接调用。
    也知道这个写法,只是函数记不住,还是百度一下才能写出来。
    如果这是面试题,能写出后一种当然好,不能的话还是老老实实的按照上面的思路来吧。
    '''
    from itertools import permutations
    for i in permutations ([1, 2, 3, 4], 3):
        print (i)

猜你喜欢

转载自blog.csdn.net/qq_32607273/article/details/81568725
今日推荐