Calculate the depreciation expenses over the given period :param useful_years: Number of years the asset will be used :param purchase_value: Purchase expenditure for the asset :param residual_value: Residual value of the asset at the end of its useful life :return: A list of ann
(
useful_years: int,
purchase_value: float,
residual_value: float = 0.0,
)
| 30 | |
| 31 | |
| 32 | def straight_line_depreciation( |
| 33 | useful_years: int, |
| 34 | purchase_value: float, |
| 35 | residual_value: float = 0.0, |
| 36 | ) -> list[float]: |
| 37 | """ |
| 38 | Calculate the depreciation expenses over the given period |
| 39 | :param useful_years: Number of years the asset will be used |
| 40 | :param purchase_value: Purchase expenditure for the asset |
| 41 | :param residual_value: Residual value of the asset at the end of its useful life |
| 42 | :return: A list of annual depreciation expenses over the asset's useful life |
| 43 | >>> straight_line_depreciation(10, 1100.0, 100.0) |
| 44 | [100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0] |
| 45 | >>> straight_line_depreciation(6, 1250.0, 50.0) |
| 46 | [200.0, 200.0, 200.0, 200.0, 200.0, 200.0] |
| 47 | >>> straight_line_depreciation(4, 1001.0) |
| 48 | [250.25, 250.25, 250.25, 250.25] |
| 49 | >>> straight_line_depreciation(11, 380.0, 50.0) |
| 50 | [30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0] |
| 51 | >>> straight_line_depreciation(1, 4985, 100) |
| 52 | [4885.0] |
| 53 | """ |
| 54 | |
| 55 | if not isinstance(useful_years, int): |
| 56 | raise TypeError("Useful years must be an integer") |
| 57 | |
| 58 | if useful_years < 1: |
| 59 | raise ValueError("Useful years cannot be less than 1") |
| 60 | |
| 61 | if not isinstance(purchase_value, (float, int)): |
| 62 | raise TypeError("Purchase value must be numeric") |
| 63 | |
| 64 | if not isinstance(residual_value, (float, int)): |
| 65 | raise TypeError("Residual value must be numeric") |
| 66 | |
| 67 | if purchase_value < 0.0: |
| 68 | raise ValueError("Purchase value cannot be less than zero") |
| 69 | |
| 70 | if purchase_value < residual_value: |
| 71 | raise ValueError("Purchase value cannot be less than residual value") |
| 72 | |
| 73 | # Calculate annual depreciation expense |
| 74 | depreciable_cost = purchase_value - residual_value |
| 75 | annual_depreciation_expense = depreciable_cost / useful_years |
| 76 | |
| 77 | # List of annual depreciation expenses |
| 78 | list_of_depreciation_expenses = [] |
| 79 | accumulated_depreciation_expense = 0.0 |
| 80 | for period in range(useful_years): |
| 81 | if period != useful_years - 1: |
| 82 | accumulated_depreciation_expense += annual_depreciation_expense |
| 83 | list_of_depreciation_expenses.append(annual_depreciation_expense) |
| 84 | else: |
| 85 | depreciation_expense_in_end_year = ( |
| 86 | depreciable_cost - accumulated_depreciation_expense |
| 87 | ) |
| 88 | list_of_depreciation_expenses.append(depreciation_expense_in_end_year) |
| 89 |
no test coverage detected