SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
Programming
Exercise:
Programming Excercises
Question:11 | ISBN:978013274719 | Edition: 6

Question

(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:

initialDepositAmount = \frac{finalAccountValue}{^{(1+monthlyInterestRate)^{numberOfMonths}}}

 

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
 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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

 

0 0

Discussions

Post the discussion to improve the above solution.