-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterest.py
30 lines (22 loc) · 904 Bytes
/
interest.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
29
30
#This method constructs an interest table given a range of interest rates, number of years, and an initial investment
#formatting will be off for large investments or large amounts of years
import sys
def interest(initial, low, high, MAXyear):
balance=0
daysInYear=365.0
percentToDecimal=100.0
#Column heading
#Spaces to center
print(" Years")
for year in range(1,MAXyear+1):
sys.stdout.write("%16d"% (year))
print()
print("Interest Rate: ")
for rate in range(low, high+1):
#row heading
sys.stdout.write(str(rate)+"% ")
for year in range(1, MAXyear+1):
balance=initial*pow((1+rate/percentToDecimal/daysInYear), daysInYear*year)
#2 decimal places because money only goes to 2 decimal places
sys.stdout.write("$%10.2f "%(balance))
print()