Building a gap analysis between forecasts
Txs Tools now has two forecasts, the original forecast forecast1 and the adjusted forecast forecast2.
The dependencies have already been defined as def dependencies(base_cost_price, base_sales_price, sales_usd), where base_cost_price = 7
and base_sales_price = 15, with forecast2 based off the following adjusted sales unit values:
Jul = 700Aug = 220Sep = 520
In this exercise, we will look at how to use a for loop to cycle between two different lists, forecast1 and forecast2 and calculate the difference ("gap") using an incremented index. It is possible to do this simultaneously as both lists have the same length.
Este exercício faz parte do curso
Financial Forecasting in Python
Instruções do exercício
- Complete the code for the adjustment forecast and original forecast with the required variables.
- Use an index (setting
indexto start at 0) to loop through yourforecast2list and print the result of the difference between theforecast2minusforecast1. - Use the
.formatmethod as part of the print statement in order to print the result, and increment yourindexby 1.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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