如果不使用Python中的這個(gè)函數(shù),我如何找到三個(gè)數(shù)字的中位數(shù)還有另一種方法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貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
對(duì)于較大的數(shù)組來(lái)說(shuō)不是最有效的,但對(duì)于只有三個(gè)元素的情況就可以了:
def find_median_three_elements(my_list): return sorted(my_list)[1]
添加回答
舉報(bào)
0/150
提交
取消