加权概率
Txs Tools 是一家销售五金工具的公司,正计划从其本土市场 A 扩张到市场 B。他们已经做了一些市场调研,并获得了以下数值型概率:
| Sales Level (USD) | Probability (%) |
|---|---|
| 0 | 5 |
| 200 | 10 |
| 300 | 40 |
| 500 | 20 |
| 800 | 25 |
只有在有合理把握实现 400 及以上的销售额时,Txs Tools 才有动力扩张。为管理不同的销售预测概率,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(____))