加權機率
Txs Tools 是一家販售五金工具的公司,正考慮從其本土市場 A 擴張到市場 B。他們已進行市場研究,並得到以下數值機率:
| Sales Level (USD) | Probability (%) |
|---|---|
| 0 | 5 |
| 200 | 10 |
| 300 | 40 |
| 500 | 20 |
| 800 | 25 |
Txs Tools 只有在能有合理把握達到 400 以上的銷售額時,才會有動機擴張。為了管理不同的銷售情境機率,Txs Tools 要求你計算加權機率。
本練習屬於課程
使用 Python 進行財務預測
練習說明
- 根據機率表,為 Txs Tools 的銷售水準計算加權機率:建立合併的
sales_probability清單,將每一組配對值以用豎線字元|分隔的字串表示。 - 建立一個迴圈走訪清單,計算加權機率。
for迴圈應逐一取出清單中的每個pair,並依據分隔配對的字元來切割為parts。
- 印出結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the combined list for sales and probability
sales_probability = ['0|0.05', ____, ____, ____, ____]
weighted_probability = 0
# Create a for loop to calculate the weighted probability
for ____ in sales_probability:
parts = pair.____('____')
weighted_probability += ____(parts[0]) * ____(parts[1])
# Print the weighted probability result
print("The weighted probability is {}.".format(____))