開始使用免費開始

建立兩個預測之間的落差分析

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 的差值結果。
  • 在 print 敘述中使用 .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
編輯並執行程式碼