Salaries

Save all functions into the same file named salaries.py.

  1. Write the function apply_percentage() that given a quantity and a percentage, returns the result of applying that percentage to the given quantity.

  2. Write the function lustrum() that given two different years (the first year lower than the second one) returns the number of full 5 year periods (lustrum) that there are between them. For example: between 2003 and 2016 there are two lustrums.

  3. To calculate the salary of its workers, a company starts from a fixed base salary, and a variable salary made of two parts: the first one is calculated applying a percentage to the quantity of sales made by that worker and the second part is calculated from a bonus that is applied by each full lustrum since the worker started to work for the company.

    Write the function salary() that takes the fixed base salary, the sales, the applied percentage, the seniority bonus, (all float), the year in which the worker was hired by the company and the present year (int, indicating the century), returns the final salary applying the explained method. This function must call both previous functions.

These functions must pass the following doctest:

>>> round(apply_percentage (125, 6.5), 2)
8.12
>>> round(apply_percentage (144.5, 2.1), 2)
3.03
>>> lustrum (2003, 2017)
2
>>> lustrum (2001, 2016)
3
>>> round(salaries (1000.0, 79876.43, 1.1, 103.2, 2015, 2018), 2)
1878.64
>>> round(salaries (1651.5, 153876.43, 0.85, 103.2, 2006, 2018), 2)
3165.85

Note

You can download the file with tests salaries.txt

Solution

A solution of these functions is provided in file salaries.py.