1. 程式人生 > >Python3練習題 001:4個數字求不重復的3位數

Python3練習題 001:4個數字求不重復的3位數

append itertools bold rto tool col 不重復 () com

#Python練習題 001:4個數字求不重復的3位數
#方法一
import itertools
res = []
[res.append(i[0]*100 + i[1]*10 + i[2]) for i in itertools.permutations(range(1,5),3)]
print(res, end = ‘,‘)

"""
參考
https://www.cnblogs.com/iderek/p/5952126.html
"""

#方法二
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if i!=j and i!=k and j!=k:
res=i*100+j*10+k
print(res, end=\t‘)
print()

Python3練習題 001:4個數字求不重復的3位數