In 1990 Grandmother earned 1200 crowns a month; her grandson earns 2600 in 2020. Who earned more? Only a price index can say, because a crown bought more in 1990.
index maps calendar years to the value of a price index (any base: the year that reads 100, if any, does not matter). An amount a in year s is worth, in the money of year y,
a \cdot \frac{\text{index}_y}{\text{index}_s}
and rebasing the index to year y means dividing every value by \text{index}_y and multiplying by 100, so year y reads 100 and every ratio between years stays the same.
Write real_wages(index, wages, base_year) where wages maps some years to a nominal wage. Return a pair of dicts (rebased, real):
rebased: every year ofindex, mapped to its rebased value withbase_yearat 100;real: every year ofwages, mapped to that wage expressed inbase_year's money.
Examples
Input: index = {1990: 62.0, 2000: 80.6, 2010: 100.0, 2020: 124.0}
wages = {1990: 1200, 2020: 2600}, base_year = 2020
Output: ({1990: 50.0, 2000: 65.0, 2010: 80.64516129032258, 2020: 100.0},
{1990: 2400.0, 2020: 2600.0})
Explanation: prices doubled from 1990 (62) to 2020 (124), so 1200 crowns of 1990 buy
what 2400 crowns bought in 2020. The grandson's wage is higher in real terms too.
Input: the same index and wages, base_year = 1990
Output: ({1990: 100.0, 2000: 130.0, 2010: 161.29032258064515, 2020: 200.0},
{1990: 1200.0, 2020: 1300.0})
Constraints
base_yearand every year ofwagesare years ofindex- floats are compared with a tolerance of
1e-6
Goals
- Rebase a price index so that a chosen year reads 100
- Convert an amount of money from one year into another year's money
- Compare wages from different years in the same money