Python 练习实例1

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

#1-1
lst = range(1, 5)
time = 0
for m in lst:
    for n in lst:
        for k in lst:
            if m!=n and m!=k and n!= k:
                time += 1
                print(m, n, k, 'time='+ str(time))
                #print(str(m)+str(n)+str(k), 'time='+ str(time))

#1-2
lst1 = str('1234')
time = 0
for m in lst1:
    for n in lst1:
        for k in lst1:
            if m!=n and m!=k and n!= k:
                time += 1         
                print(m+n+k, 'time='+ str(time))

总感觉这种是笨方法,想用random但是不知道用哪个函数。。以后想到了,再加

你可能感兴趣的:(python,实例,100-1)