|
发表于 2019-8-3 14:08:13
|
显示全部楼层
- import random
- list1 = [random.randint(1,100) for i in range(10)]
- print(list1)
- max = list1[0]
- min = list1[0]
- for i in range(len(list1)):
- if list1[i] > max:
- max = list1[i]
- else:
- continue
- print('最大值是{}'.format(max))
- for i in range(len(list1)):
- if list1[i] < min:
- min = list1[i]
- else:
- continue
- print('最小值是{}'.format(min))
- list1[list1.index(max)] = list1[0]
- list1[0] = max
- print(list1)
- list1[list1.index(min)] = list1[-1]
- list1[-1] = min
- print(list1)
复制代码
[92, 50, 48, 62, 42, 53, 98, 23, 4, 69]
[98, 50, 48, 62, 42, 53, 92, 23, 69, 4] |
|