开始使用免费开始使用

构建两个预测之间的差距分析

Txs Tools 现在有两个预测:原始预测 forecast1 和调整后预测 forecast2

依赖关系已定义为 def dependencies(base_cost_price, base_sales_price, sales_usd),其中 base_cost_price = 7base_sales_price = 15,并且 forecast2 基于以下调整后的销售数量:

  • Jul = 700
  • Aug = 220
  • Sep = 520

在本练习中,您将使用 for 循环在两个列表 forecast1forecast2 之间逐项遍历,并使用递增的索引计算两者的差值("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
编辑并运行代码