Travel expenses (2 points)¶
A company wants to analyse the travel expenses of its employees and
has obtained a list with the travel expenses for each
of them. Each item of this list corresponds to the travel expenses of
a month.
Write the modifier function expenses() that takes a list,
te, as described, and modifies it in such a way that each
element accumulates all the previous amounts, i. e., the first element
does not change and the next ones will have the value: \(te_i =
\sum_{n=0}^{i} te_n, 1\leq i<len(te)\). Moreover this list must include a
new item at the end with the average of the expenses.
Save this function in file expenses.py.
Examples:
>>> le1 = [500, 250, 1000]
>>> expenses(le1)
>>> le1[:-1]
[500, 750, 1750]
>>> round(le1[-1], 1)
583.3
>>> le2 = [441, 244, 1023, 156, 1078, 367]
>>> expenses(le2)
>>> le2[:-1]
[441, 685, 1708, 1864, 2942, 3309]
>>> round(le2[-1], 1)
551.5
Note
More tests are provided in file test-expenses.txt.