PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class ComplexInterest:
'''
class takes monthy investment, time period and average yearly interest rate to calculate the profitability
'''
def __init__(self,monthly_investment:int,period_years:int,avg_interest_yearly:float) -> None:
self.year_investment = monthly_investment * 12
self.period_years = period_years
self.avg_interest_yearly = avg_interest_yearly
self.total_invested_period = 0
self.total_profit_period = 0
@property
def report(self):
accumulation = 0
profit = self.year_investment * self.avg_interest_yearly
print(f"Investing {self.year_investment/12} $ a month for {self.period_years} years with {self.avg_interest_yearly*100} % average yearly interest.")
print('-'*45)
for y in range(1,self.period_years+1):
accumulation += round(self.year_investment + profit,2)
profit = round(accumulation * self.avg_interest_yearly,2)
print(f"{y} year: {profit}$ profit total: {accumulation} $")
@property
def totals(self):
profit = self.year_investment *self.avg_interest_yearly
accumulation = 0
for i in range(1,self.period_years+1):
Enter to Rename, Shift+Enter to Preview
OUTPUT
Запуск