【Python第二章】2.13题
# 已知列表 nums = [1,-200,3,400,5,-8,9,15,-100,2]
# 找出最大 第二大 最小 第二小 的元素
nums = [1, -200, 3, 400, 5, -8, 9, 15, -100, 2]
max = maxs = min = mins = nums[0]
for i in range(len(nums)):
if nums[i] > max:
max = nums[i]
elif nums[i] < min:
min = nums[i]
elif max > nums[i] > maxs:
maxs = nums[i]
elif min < nums[i] < mins:
mins = nums[i]
print(f'最大值:{max}')
print(f'第二大值:{maxs}')
print(f'最小值:{min}')
print(f'第二小值:{mins}')
Views: 466