-
-
Notifications
You must be signed in to change notification settings - Fork 505
Expand file tree
/
Copy pathcalculateCompoundInterest.py
More file actions
21 lines (16 loc) · 841 Bytes
/
calculateCompoundInterest.py
File metadata and controls
21 lines (16 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pyinputplus as pyip
#User input variables for calculating compound interest
time = pyip.inputInt('How many years will you be saving? Enter amount: ')
principal = pyip.inputFloat('How much money is currently in your account? Enter amount: ')
monthly_invest = pyip.inputFloat('How much money do you plan on investing monthly? Enter amount: ')
interest_percent = pyip.inputFloat('''What do you estimate will be the yearly interest of this investment?\n
Enter rate as percent (%): ''')
#Interest conversion
rate = interest_percent/100
#Calculate final amount after investing and accruing interest:
balance = principal
for year in range(time):
balance = balance * (1 + rate)
balance += monthly_invest * 12
#Print final result
print(f"This is how much money you would have in your account after {time} years: ${balance:,.2f}")