共計 376 個字符,預計需要花費 1 分鐘才能閱讀完成。
要將三個數排列組合,可以使用 permutations
函數來獲得所有可能的排列。下面是一個示例代碼:
from itertools import permutations
# 輸入三個數字
num1 = int(input(" 請輸入第一個數字:"))
num2 = int(input(" 請輸入第二個數字:"))
num3 = int(input(" 請輸入第三個數字:"))
# 使用 permutations 函數獲得所有排列
permutations_list = list(permutations([num1, num2, num3]))
# 打印所有排列
for permutation in permutations_list:
print(permutation)
這段代碼會要求用戶輸入三個數字,然后使用 permutations
函數獲得所有可能的排列,并將其打印出來。
丸趣 TV 網 – 提供最優質的資源集合!
正文完