You may use the following Python script to determine the final amount of a monthly savings plan. You are able to set the principle amount, the monthly payment, the interest rate and the term. The script also has the ability to compound the interest monthly, quarterly or annually.
def calculate_final_amount(principal, monthly_deposit, annual_interest_rate, num_of_years, compounding_period):
# Convert interest rate to monthly rate
monthly_interest_rate = (annual_interest_rate / 100) / 12
# Calculate the number of months
num_of_months = num_of_years * 12
# Calculate the number of compounding periods
if compounding_period == "monthly":
num_of_compounding_periods = num_of_months
elif compounding_period == "quarterly":
num_of_compounding_periods = num_of_years * 4
elif compounding_period == "annually":
num_of_compounding_periods = num_of_years
else:
raise ValueError("Invalid compounding period entered!")
# Calculate the final amount
final_amount = principal
for _ in range(num_of_compounding_periods):
final_amount += monthly_deposit
final_amount *= (1 + monthly_interest_rate)
return round(final_amount, 2)
# Example usage
principal_amount = float(input("Enter the principal amount: "))
monthly_deposit_amount = float(input("Enter the monthly deposit amount: "))
annual_interest_rate = float(input("Enter the annual interest rate: "))
num_of_years = int(input("Enter the number of years: "))
compounding_period = input("Enter the compounding period (monthly, quarterly, or annually): ")
final_amount = calculate_final_amount(
principal_amount, monthly_deposit_amount, annual_interest_rate, num_of_years, compounding_period
)
print("The final amount after {} years is: {:.2f}".format(num_of_years, final_amount))