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:
Tony Gaddis
Chapter:
Value Returning Functions And Modules
Exercise:
Programming Exercises
Question:10 | ISBN:9780132576376 | Edition: 2

Question

Future Value
Suppose you have a certain amount of money in a savings account that earns compound monthly interest and you want to calculate the amount that you will have after a specific
number of months. The formula is 

F=P\times \left ( 1+i \right )^{^{t}}

The terms in the formula are as follows:
• F is the future value of the account after the specified time period.
• P is the present value of the account.
• i is the monthly interest rate.
• t is the number of months.
Write a program that prompts the user to enter the account’s present value, monthly interest rate, and number of months that the money will be left in the account. The program should
pass these values to a function that returns the future value of the account after the specified number of months. The program should display the account’s future value.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Future Value Program code:

#The method 'calculateFutureValue' is used to
#returns the future value of the account after
#the specified number of months 
#from 1 through 100.
def calculateFutureValue(presentValue, monthlyInterestRate, months):
    future_value = presentValue * (1 + monthlyInterestRate) ** months
    return future_value

# Prompt and read the user inputs
#Prompts the user to enter the account’s present value,
#monthly interest rate, and number of months that 
#the money will be left in the account 
presentValue = float(input("Enter the present value of the account: "))
monthlyInterestRate = float(input("Enter the monthly interest rate (in decimal form): "))
months = int(input("Enter the number of months: "))

# Calculating future value
futureValue = calculateFutureValue(presentValue, monthlyInterestRate, months)

# Displaying the future value
print("The future value of the account after", months, "months is:", futureValue)

Executed Output:

   
Enter the present value of the account: 
5000
Enter the monthly interest rate (in decimal form): 
16
Enter the number of months: 
12
The future value of the account after 12 months is: 2.913111186148805e+18

 

0 0

Discussions

Post the discussion to improve the above solution.