Answer:
yearsUntilRetire =0
expectedInterest =-1.00
initialAmount =-1.0
expectedAmountToAdd = -1.00
while yearsUntilRetire < 1 or yearsUntilRetire > 70:
yearsUntilRetire = int(input("Number of year until you retire between 1 to 70: "))
while expectedInterest <0 :
expectedInterest = float(input("enter the expected rate : "))
if expectedInterest >= 10:
doubleCheckRate = input("do you really expect {} interest rate: ".format(expectedInterest)).lower()
if doubleCheckRate == "false":
expectedInterest =-1.00
while initialAmount < 0:
initialAmount = float(input("Enter positive initial amount for IRA: "))
while expectedAmountToAdd < 0 or expectedAmountToAdd > 2500:
expectedAmountToAdd = float(input("Enter positive IRA amount to be added each year between 0 to $2500: "))
finalContribution =initialAmount
for i in range(yearsUntilRetire):
finalContribution = finalContribution + finalContribution * (expectedInterest/100.00) + expectedAmountToAdd
if (i+1) % 5 == 0:
print("Contribution after year {} is ${:,.2f}.".format(i+1,finalContribution))
print("Final Contribution is ${:,.2f}.".format(finalContribution))
Explanation:
- Use a loop to get the valid input from the user for years until retire between 1 to 70
.
- Get the valid input for expected rate
.
- Check if expected rate is greater than or equal to 10 then ask the user again if one expect such high rate
.
- Use a loop to get valid IRA initial Contribution
.
- Use a loop to get expected Amount to add regularly in IRA
.
- Iterate over numbers of year and print the data after 5 years
.