a524: 手機之謎
#a524: 手機之謎
'''
輸入說明
輸入為一個 n (n<=8),代表鄭學長的密碼位數。
輸出說明
輸出所有可能的密碼,依字典順序反向排列(因為你覺得他的密碼應該在後半段)。
範例輸入 #1
3
2
範例輸出 #1
321
312
231
213
132
123
21
12
import itertools
inp_list = [1,2, 3]
permutations = list(itertools.permutations(inp_list))
print(permutations)
print('\n')
inp_list = [1,2]
permutations = list(itertools.permutations(inp_list))
print(permutations)
'''
import itertools
a_list=[]
permutations=[]
print ('a524: 手機之謎')
while True:
try:
a_list=[]
permutations=[]
N= int(input('請輸入一個十進制正整數 N (N<=8) --> ')) #
for i in range(1,N+1):
a_list.append(i)
permutations = list(itertools.permutations(a_list))
print(permutations)
except:
break
Python 3.7.9 (bundled)
>>> %Run a524.py
a524: 手機之謎
請輸入一個十進制正整數 N (N<=8) --> 3
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
請輸入一個十進制正整數 N (N<=8) --> 4
[(1, 2, 3, 4), (1, 2, 4, 3), (1, 3, 2, 4), (1, 3, 4, 2), (1, 4, 2, 3), (1, 4, 3, 2), (2, 1, 3, 4), (2, 1, 4, 3), (2, 3, 1, 4), (2, 3, 4, 1), (2, 4, 1, 3), (2, 4, 3, 1), (3, 1, 2, 4), (3, 1, 4, 2), (3, 2, 1, 4), (3, 2, 4, 1), (3, 4, 1, 2), (3, 4, 2, 1), (4, 1, 2, 3), (4, 1, 3, 2), (4, 2, 1, 3), (4, 2, 3, 1), (4, 3, 1, 2), (4, 3, 2, 1)]
請輸入一個十進制正整數 N (N<=8) --> 2
[(1, 2), (2, 1)]
請輸入一個十進制正整數 N (N<=8) -->
>>>
沒有留言:
張貼留言