Electricity Bill ================ The electricity bill is calculated depending of a number of parameters: - The current **gas** price (GasP): :class:`float` value. - The current **renewable energies** price (RenewEP): :class:`float` value. - The electricity consumed in kWh (**Consum**): :class:`int` value. - The **day** of the week (Day): :class:`int` value. The bill is calculated by multipling *Consum* by the **price of the electricty** (in kWh), namely EP, which is determined by the following rules: - When GasP is strictly greater that the double of the RenewEP, then EP is GasP + RenewEP. In this case the following discounts are applied: - 25% discount is applied if *Consum* is greater than or equal to 100 kWh. - 10% discount is applied if *Consum* is between 10 kWh and 100 kWh (the first included and the later excluded). - No discount is applied otherwise. - When GasP is lower than or equal to the double of RenewEP, then EP is the maximum between GasP and RenewEP. In this case a discount of 15% is applied but only if *Consum* is greater than 100 kWh. - The bill is cut in half during the weekend (saturday and sunday), indepedently of the rest of the values. The data provided to calculate the bill might contain errors. Hence, before calculating the bill, the data must be checked to determine whether is valid or not. If some data is incorrect then an **error code** (:class:`int`) must be generated according to the following format: - If any of the prices is negative then the *hundreds digit* in the error code must be 1. - If *Consum* is null or negative then the *tens digit* must be 1. - If the int in Day is not correct then the *units digit* must be 1. For example, in case where the Gas price is negative and the day is 9 then the error code generated should be **101**. In case everything is incorrect (some price is negative, *Consum* is 0 and the day is not between 1 and 7, then the error code should be **111**. Implement the following Python functions in the module :mod:`ebill` (file :file:`ebill.py`). ------------------------------------------------------------------------------------------------------------------------- The first funcion is: .. function:: ebill_check(GasP, RenewEP, Consum, Day) such that **given** `GasP`, `RenewEP`, `Consum` and `Day` as specified above. **returns** two values: - a :class:`bool` which value is `True` if there is an error or `False` otherwise. - an :class:`int` with either the *error code* as described above, or 0 if there is no error. For example: .. literalinclude:: ebill_check-test.txt :language: python3 :start-after: --ini :end-before: --fi Additional doctests for validation are available in the :download:`ebill_check-test.txt` file. ------------------------------------------------------------------------------------------------------------------------- The second funcion is: .. function:: ebill_eval(GasP, RenewEP, Consum, Day) such that **given** `GasP`, `RenewEP`, `Consum` and `Day` as specified above, and all are valid values. **calculates** the final price to pay of the electricity bill and **returns** the integer part of that amount. For example: .. literalinclude:: ebill_eval-test.txt :language: python3 :start-after: --ini :end-before: --fi Additional doctests for validation are available in the :download:`ebill_eval-test.txt` file. ------------------------------------------------------------------------------------------------------------------------- The third (and main) funcion is: .. function:: ebill_calc(GasP, RenewEP, Consum, Day) such that **given** `GasP`, `RenewEP`, `Consum` and `Day` as specified above, **returns** two values: - a :class:`bool` which value is `True` if there is an error and `False` otherwise. - an :class:`int` that will be either the *error code* if the previous value is `True`, or the integer part of the final price to pay calculated as specified above, otherwise. For example: .. literalinclude:: ebill_calc-test.txt :language: python3 :start-after: --ini :end-before: --fi Additional doctests for validation are available in the :download:`ebill_calc-test.txt` file. .. warning:: The last function implementation **must** call both previous functions. It is in our own interest since the code for this last function becomes much more simple if you use those.