如果不使用Python中的这个函数,我如何找到三个数字的中位数还有另一种方法median_1 = stats.median(alpha_1) enter code heredef median(alpha_1): #median_1 = sorted(alpha) median_1 = statistics.median(alpha_1) return median_1if __name__ == "__main__": # FIXME 1: Print the statement where you say what the program is going to do num_1 = int(input("Input first number:\n")) num_2 = int(input("Input second number:\n")) num_3 = int(input("Input third number:\n")) # FIXME 2: Propmt the user to input 3 numbers c = num_1, num_2, num_3 f = median(c) print("The median is",f)
1 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
对于较大的数组来说不是最有效的,但对于只有三个元素的情况就可以了:
def find_median_three_elements(my_list): return sorted(my_list)[1]
添加回答
举报
0/150
提交
取消