Retirement Calculator


This is an old retirement calculator I did for school. It prompts the user for the initial investment, annual interest rate, and number of years, and then calculates the compound interest using the following formula:

The compound_interest() function takes in three arguments: the principal (initial investment), the annual interest rate, and the number of years. It returns the total investment after the given number of years.

You can use this script to calculate the compound interest for a retirement investment by setting the annual interest rate to 7.5% (or whatever rate you want to use) and the number of years to the number of years until retirement.

import math

def retire(current_age, retire_age, salary):
    years_until_retirement = retire_age - current_age
    savings_per_year = salary / 10 # assuming you need to save 10% of your salary per year to retire comfortably
    total_savings = savings_per_year * years_until_retirement * 12 # multiply by 12 to convert to monthly savings
    return years_until_retirement, savings_per_year, total_savings

current_age = int(input("Enter your current age: "))
retire_age = int(input("Enter the age at which you want to retire: "))
salary = int(input("Enter your current yearly salary: "))

years_until_retirement, savings_per_year, total_savings = retire(current_age, retire_age, salary)

print("You have {} years until retirement.".format(years_until_retirement))
print("You need to save ${:,.2f} per year to retire comfortably.".format(savings_per_year))
print("In total, you will need to save ${:,.2f} to retire comfortably.".format(total_savings))


If I make $45k/year I can retire with $2 million a year based on a 7.5% interest rate. Success!

Enter your current age: 25
Enter the age at which you want to retire: 65
Enter your current yearly salary: 45000
Enter the annual interest rate (in percentage): 7.5
You have 40 years until retirement.
You need to save $4,500.00 per year to retire comfortably.
In total, you will need to save $2,160,000.00 to retire comfortably.

Leave a Reply