Retirement Age Calculator
Build a function retirement_age(PMT, i, FV, start_age) that calculates the (whole) age at which your customer can retire, if they:
•invest an amount, PMT at the END of every YEAR (with the first payment made exactly one year from now),
•at an interest rate of i% per year, compounded annually,
•they require an amount of AT LEAST FV in order to be able to afford retirement and
•they just turned start_age years old.
Solve this using python.
Answers
Answer:
# Importing required mathematical library
import math
def retirement_age(PMT,i,FV,start_age):
# Rate of intereset to be converted from percentage to number
roi = i*0.01
# Interim calculations to be used in the compound interest formula
val1 = FV/PMT
val2 = 1 + roi
#Number of years as per the compound interest formula
no_of_year = math.log10(val1)/math.log10(val2)
return no_of_year
PMT = float(input('Please enter the principle amount: '))
i = float(input('Please enter the rate of interest: '))
FV = float(input('Please enter the desired final amount: '))
start_age = int(input('Please enter your age: '))
ret_age = round(retirement_age(PMT,i,FV,start_age) + start_age)
print(f'You can retire at the age of {ret_age}')
Sample Output:
Please enter the principle amount: 1000
Please enter the rate of interest: 10
Please enter the desired final amount: 100000
Please enter your age: 30
You can retire at the age of 78