Since Week One

Data with PythonMedium+10 XP+10

Since Week One

A shopper tracks the prices of a few items every week. The prices come as a grid: one row per week and one column per item. The first row is week one.

They want to see how each price has moved since week one, as a percentage of that item's week-one price.

For an item whose week-one price was p, a later price q has changed by

q−pp×100\frac{q - p}{p} \times 100pq−p​×100

per cent. A rise is positive and a fall is negative.

Task: write change_since_first(prices) and return a grid of the same shape, as a list of lists: every price turned into its percentage change since week one, rounded to 1 decimal place. The first row is all 0.0.

No week-one price is 0.

Examples

prices = [[2.0, 4.0, 1.5], [2.2, 3.6, 1.5], [2.5, 4.4, 1.8]]
returns [[0.0, 0.0, 0.0], [10.0, -10.0, 0.0], [25.0, 10.0, 20.0]]
prices = [[10, 20], [12, 15], [9, 26]]
returns [[0.0, 0.0], [20.0, -25.0], [-10.0, 30.0]]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run