python基础题目100例之六十七
- 输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出
import random
# 输出一个随机的列表
begin = 1
end = 20
needcount = 10
resultlist = random.sample(range(begin,end),needcount)
print(resultlist)
max_num = max(resultlist)
min_num = min(resultlist)
resultlist[resultlist.index(max_num)] = resultlist[0]
resultlist[0] = max_num
resultlist[resultlist.index(min_num)] = resultlist[-1]
resultlist[-1] = min_num
print(resultlist)