@@ -89,27 +89,24 @@ def straight_line_depreciation(
8989
9090 return list_of_depreciation_expenses
9191
92-
93- def declining_balance_depreciation (
94- useful_years : int ,
92+ def declining_balance_depreciation (useful_years : int ,
9593 purchase_value : float ,
96- residual_value : float = 0.0 ,
97- ):
94+ residual_value : float = 0.0 ,):
9895 """
9996 Calculate the depreciation expenses over the given period using the declining balance method
10097 :param useful_years: Number of years the asset will be used
10198 :param purchase_value: Purchase expenditure for the asset
10299 :param residual_value: Residual value of the asset at the end of its useful life
103- :return: A list of annual depreciation expenses over the asset's useful life
100+ :return: A list of annual depreciation expenses over the asset's useful life, rounded to the nearest cent
104101
105102 >>> declining_balance_depreciation(10,1100.0,100.0)
106- [234.52721358355052 , 184.52447366421927 , 145.1826458038188 , 114.22875363922134 , 89.87443427365002 , 70.71261550765269 , 55.636222162002895 , 43.774214745666626 , 34.44126509920373 , 27.098161521014077 ]
103+ [234.53 , 184.52 , 145.18 , 114.23 , 89.87 , 70.71 , 55.64 , 43.77 , 34.44 , 27.1 ]
107104 >>> declining_balance_depreciation(6,1250.0,50.0)
108- [518.9955654467834 , 303.51044788404226 , 177.49398666917426 , 103.79911308935672 , 60.70208957680846 , 35.49879733383485 ]
105+ [519.0 , 303.51 , 177.49 , 103.8 , 60.7 , 35.5 ]
109106 >>> declining_balance_depreciation(4,1001.0)
110107 [1001.0, 0.0, 0.0, 0.0]
111108 >>> declining_balance_depreciation(11,380.0,50.0)
112- [63.98359103909348 , 53.21017019104619 , 44.25075501045555 , 36.799907084771036 , 30.60361707111676 , 25.45064517902371 , 21.165319724245478 , 17.601548246751307 , 14.637837023922344 , 12.173149187513005 , 10.123460242061142 ]
109+ [63.98 , 53.21 , 44.25 , 36.8 , 30.6 , 25.45 , 21.17 , 17.6 , 14.64 , 12.17 , 10.12 ]
113110 >>> declining_balance_depreciation(1,4985,100)
114111 [4885.0]
115112 """
@@ -132,40 +129,37 @@ def declining_balance_depreciation(
132129 if purchase_value < residual_value :
133130 raise ValueError ("Purchase value cannot be less than residual value" )
134131
135- depreciation_rate = 1 - (residual_value / purchase_value ) ** (1 / useful_years )
132+ depreciation_rate = 1 - (( residual_value / purchase_value ) ** (1 / useful_years ) )
136133 book_value = purchase_value
137134
138135 list_of_depreciation_expenses = []
139136
140- for i in range (1 , useful_years + 1 ):
141- new_book_value = purchase_value * (( 1 - depreciation_rate ) ** i )
142- list_of_depreciation_expenses .append (book_value - new_book_value )
137+ for i in range (1 , useful_years + 1 ):
138+ new_book_value = book_value * (1 - depreciation_rate )
139+ list_of_depreciation_expenses .append (round ( book_value - new_book_value , 2 ) )
143140 book_value = new_book_value
144-
141+
145142 return list_of_depreciation_expenses
146143
147-
148- def sum_of_years_digits_depreciation (
149- useful_years : int ,
144+ def sum_of_years_digits_depreciation (useful_years : int ,
150145 purchase_value : float ,
151- residual_value : float = 0.0 ,
152- ):
146+ residual_value : float = 0.0 ,):
153147 """
154148 Calculate the depreciation expenses over the given period using the sum of years' digits method
155149 :param useful_years: Number of years the asset will be used
156150 :param purchase_value: Purchase expenditure for the asset
157151 :param residual_value: Residual value of the asset at the end of its useful life
158- :return: A list of annual depreciation expenses over the asset's useful life
159-
160- >>> declining_balance_depreciation (10,1100.0,100.0)
161- [234.52721358355052, 184.52447366421927 , 145.1826458038188, 114.22875363922134, 89.87443427365002, 70.71261550765269, 55.636222162002895, 43.774214745666626, 34.44126509920373, 27.098161521014077 ]
162- >>> declining_balance_depreciation (6,1250.0,50.0)
163- [518.9955654467834, 303.51044788404226, 177.49398666917426, 103.79911308935672, 60.70208957680846, 35.49879733383485 ]
164- >>> declining_balance_depreciation (4,1001.0)
165- [1001.0, 0.0, 0.0, 0.0 ]
166- >>> declining_balance_depreciation (11,380.0,50.0)
167- [63.98359103909348, 53.21017019104619, 44.25075501045555, 36.799907084771036, 30.60361707111676, 25.45064517902371, 21.165319724245478, 17.601548246751307, 14.637837023922344, 12.173149187513005, 10.123460242061142 ]
168- >>> declining_balance_depreciation (1,4985,100)
152+ :return: A list of annual depreciation expenses over the asset's useful life, rounded to the nearest cent
153+
154+ >>> sum_of_years_digits_depreciation (10,1100.0,100.0)
155+ [181.82, 163.64 , 145.45, 127.27, 109.09, 90.91, 72.73, 54.55, 36.36, 18.18 ]
156+ >>> sum_of_years_digits_depreciation (6,1250.0,50.0)
157+ [342.86, 285.71, 228.57, 171.43, 114.29, 57.14 ]
158+ >>> sum_of_years_digits_depreciation (4,1001.0)
159+ [400.4, 300.3, 200.2, 100.1 ]
160+ >>> sum_of_years_digits_depreciation (11,380.0,50.0)
161+ [55.0, 50.0, 45.0, 40.0, 35.0, 30.0, 25.0, 20.0, 15.0, 10.0, 5.0 ]
162+ >>> sum_of_years_digits_depreciation (1,4985,100)
169163 [4885.0]
170164 """
171165
@@ -191,15 +185,20 @@ def sum_of_years_digits_depreciation(
191185
192186 list_of_depreciation_expenses = []
193187
194- for i in range (1 , useful_years + 1 ):
195- depreciation_value = (
196- (useful_years - (i - 1 )) / digits_sum * (purchase_value - residual_value )
197- )
198- list_of_depreciation_expenses .append (depreciation_value )
188+ for i in range (1 , useful_years + 1 ):
189+ depreciation_value = (useful_years - (i - 1 )) / digits_sum * (purchase_value - residual_value )
190+ list_of_depreciation_expenses .append (round (depreciation_value , 2 ))
199191
192+
200193 return list_of_depreciation_expenses
201194
202195
196+
197+
198+
199+
200+
201+
203202if __name__ == "__main__" :
204203 import doctest
205204 doctest .testmod ()
0 commit comments