(Financial application: investment amount) Suppose you want to deposit a certain amount of money into a savings account with a fixed annual interest rate.
What amount do you need to deposit in order to have $5,000 in the account after three years? The initial deposit amount can be obtained using the following
formula:
Write a program that prompts the user to enter final account value, annual interest rate in percent, and the number of years, and displays the initial deposit amount. Here is a sample run:
Enter final account value: 1000
Enter annual interest rate in percent: 4.25
Enter number of years: 5
Initial deposit value is 808.8639197424636
Financial application: investment amount Program Code:
# Prompt the user to enter the final account value
finalAccountValue = float(input("Enter final account value: "))
# Prompt the user to enter the annual interest rate in percent
annualIntrestRate = float(input("Enter annual interest rate in percent: "))
# Prompt the user to enter the number of years
numYears = int(input("Enter number of years: "))
# Convert the annual interest rate from percent to decimal
interestRateDecimal = annualIntrestRate / 100
# Calculate the monthly interest rate
monthlyInterestRate = interestRateDecimal / 12
# Calculate the number of months
numberOfMonths = numYears * 12
# Calculate the initial deposit amount using the formula
initialDepositAmount = finalAccountValue / ((1 + monthlyInterestRate) ** numberOfMonths)
# Display the initial deposit amount
print("Initial deposit value is", initialDepositAmount)
Executed Output:
Enter final account value: 1000
Enter annual interest rate in percent: 4.25
Enter number of years: 5
Initial deposit value is 808.8639197424636