開始使用免費開始

量測一個樣本

來用硬幣擲投的樣本來計算一些機率吧。你會計算絕對與相對次數,並用樣本資料的分佈來對照理論值。

陣列 sample_of_two_coin_flips 包含 1,000 次實驗,每次實驗擲兩枚公平硬幣。對於每次實驗,我們記錄兩次擲投中出現正面的次數:0、1,或 2。

我們已為你預先載入 scipy.stats 函式庫中的 binom 物件,以及 find_repeats()relfreq() 方法。你需要用這些來計算本練習中的機率。

本練習屬於課程

Python 機率基礎

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Count how many times you got 2 heads from the sample data
count_2_heads = ____(sample_of_two_coin_flips).counts[2]

# Divide the number of heads by the total number of draws
prob_2_heads = count_2_heads / ____

# Display the result
print(prob_2_heads)
編輯並執行程式碼