题目
用时
没算,大概十几分钟吧
思路
取最大最小都有现成的方法可以用
自己写一个取中位数的就好了
取中位数要注意题目要求
是整数就输出整数
小数四舍五入保留一位
满分代码
def get_median(my_list):
# 取list的中位数,整数或保留一位小数
my_list.sort()
half_len = len(my_list) // 2
sum_two = my_list[half_len] + my_list[~half_len]
if sum_two % 2 == 0:
return int(sum_two / 2)
else:
return round(sum_two / 2, 1)
if __name__ == "__main__":
length = int(input())
# 输入序列长度
array = list(map(int, input().split(' ')))
# 分割,转int
result = []
# 记录最大值最小值中位数
result.append(max(array))
result.append(get_median(array))
result.append(min(array))
for r in result:
print(r, end=' ')