构建两个预测之间的差距分析
Txs Tools 现在有两个预测:原始预测 forecast1 和调整后预测 forecast2。
依赖关系已定义为 def dependencies(base_cost_price, base_sales_price, sales_usd),其中 base_cost_price = 7、base_sales_price = 15,并且 forecast2 基于以下调整后的销售数量:
Jul = 700Aug = 220Sep = 520
在本练习中,您将使用 for 循环在两个列表 forecast1 和 forecast2 之间逐项遍历,并使用递增的索引计算两者的差值("gap")。由于两个列表长度相同,可以同时完成该操作。
本练习是课程的一部分
Python 金融预测
练习说明
- 使用所需变量,补全调整后预测和原始预测的代码。
- 使用索引(将
index设为从 0 开始)循环遍历forecast2列表,并打印forecast2减去forecast1的差值结果。 - 在打印语句中使用
.format方法输出结果,并在每次循环后将index加 1。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Set the two results
forecast1 = ____(7, 15, [700, 350, 650])
forecast2 = dependencies(____, ____, [____, ____, ____])
# Create an index and the gap analysis for the forecast
index = ____
for ____ in forecast2:
print("The gap between forecasts is {}".____(value - ____[index]))
____ += 1