❶ 如何python編程輸入若干個中間以空格隔開的整數,並從大到小進行排序,並將結果輸出(每行輸出1個數)
temp = '2 3 11'
temp = temp.split(' ')
temp = [int(v) for v in temp]
temp.sort(reverse=True)
❷ python中怎麼讓前5個升序,後五個降序,派Python中輸入十個數字,怎麼讓前五個升序
分成兩個列表分別排序,代碼如下:
s = input().split()
l1 = [ int(x) for x in s[:5] ] # 前5個數字
l2 = [ int(x) for x in s[-5:] ] # 後5個數字
l1.sort() # 前5個數字升序
l2.sort(reverse=True) # 後5個數字降序
print(l1 + l2)
運行結果如下:
輸出符合題意,望採納~
❸ python中編寫一個模塊,模塊中包含隨機生成N個元素的列表、排序列表、求最大
下面是一個 Python 模塊的例子,它包含了隨機生成 N 個元素的列表、排序列表、求最大值三個功能:
這樣,就可以使用 my_mole 模塊中的函數來生成隨機列表、排序列表、求出最大值。
❹ 【問題描述】 輸入n的值和n個數,進行排序並輸出。 【輸入形式】 首先輸入整數個數n; 接著輸入n
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
a.sort()
print(a)
❺ 如何用Python列出N個數字的所有排列組合
>> from itertools import combinations, permutations
>> permutations([1, 2, 3], 2)
<itertools.permutations at 0x7febfd880fc0>
# 可迭代對象
>> list(permutations([1, 2, 3], 2)) #排列
[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
>> list(combinations([1, 2, 3], 2)) #組合
[(1, 2), (1, 3), (2, 3)]