Energy consumption (3 points)¶
Write the modifier function energy() that takes a list,
m, of energy consumptions (in kWh) that correspond to the monthly
energy consumptions of a company, and modifies it in such a way
that each element, except the last one, now contains the difference
between the following and the current month, i. e., \(m_i =
m_{i+1} - m_i, 0<=i<len(m)-1\). The last element of the list
must be 0.
Save this function to file p3.py.
Examples:
>>> lkw1 = [600, 700, 850]
>>> r = energy(lkw1)
>>> print(r)
None
>>> lkw1
[100, 150, 0]
>>> lkw2 = [502, 499, 725, 852, 840, 1010, 999, 1020]
>>> r = energy(lkw2)
>>> print(r)
None
>>> lkw2
[-3, 226, 127, -12, 170, -11, 21, 0]
Note
More tests are provided in file test-energy.txt.