If GDP rises, was more produced, or did prices just go up? Nominal GDP values each year's output at that year's prices; real GDP values each year's output at the prices of one fixed base year, so only changes in quantities move it. For year t and base year b:
\text{nominal}_t = \sum_{\text{goods}} p_t \, q_t \qquad \text{real}_t = \sum_{\text{goods}} p_b \, q_t
Pellora's economy makes a few goods. prices[good] is the list of that good's price in years 0, 1, ..., n-1 (crowns per unit) and quantities[good] the list of units produced in the same years. Both dicts have the same goods, and every list has the same length n. base is the index of the base year.
Write nominal_and_real(prices, quantities, base) that returns a pair of lists (nominal, real), each with one value per year.
Examples
Input: prices = {"fish": [2, 3, 4], "boats": [50, 55, 70]}
quantities = {"fish": [100, 110, 120], "boats": [4, 5, 5]}
base = 0
Output: ([400, 605, 830], [400, 470, 490])
Explanation: in year 2 nominal GDP is 4 * 120 + 70 * 5 = 830, but at year-0 prices the
same output is worth 2 * 120 + 50 * 5 = 490. Nominal GDP more than doubled; real GDP
grew by less than a quarter.
Input: same prices and quantities, base = 1
Output: ([400, 605, 830], [520, 605, 635])
Constraints
- numbers are compared with a tolerance of
1e-6
Goals
- Compute nominal GDP as the sum of this year's prices times this year's quantities
- Compute real GDP by valuing every year's quantities at base-year prices
- See that real GDP changes only when quantities change