-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvestment_calculator1
37 lines (33 loc) · 1.21 KB
/
Investment_calculator1
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
31
32
33
34
35
36
37
#!/bin/python3
def get_inv():
while True:
inv_amount = int(input("Enter investment amount: $"))
while inv_amount <= 0.00:
print("Sorry,input must be a postive integer, try again")
calculation()
print("Investment amount: " + str(inv_amount))
return(inv_amount)
def get_year():
while True:
years = int(input("Enter number of years: "))
while years <= 0.00:
print("Sorry input must be a positive integer, try again")
calculation()
print("Years: ", str(years))
return(years)
def get_rate():
while True:
interest_rate = float(input("Enter interest rate <ex .05>: "))
while interest_rate <= 0.00:
print("Sorry,input must be a postive decimal, try again")
calculation()
print("Your investment at ", (interest_rate), "%, is: ")
return(interest_rate)
def calculation():
inv_amount = get_inv()
num_years = get_year()
interest_rate = get_rate()
for year in range(1, num_years + 1):
inv_amount *= (1 + interest_rate)
print(f"Your investment at {interest_rate*100}% after {year} years is: ${inv_amount:.2f}")
calculation()