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:19 | ISBN:978013274719 | Edition: 6

Question

(Financial application: calculate future investment value) Write a program that reads in an investment amount, the annual interest rate, and the number of years,and displays the future investment value using the following formula:

           futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate)^numberOfMonths

For example, if you enter the amount 1000, an annual interest rate of 4.25%,and the number of years as 1, the future investment value is 1043.33. Here is a sample run:

Enter investment amount:1000
Enter annual interest rate:4.25
Enter number of years:1
Accumulated value is 1043.33
 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Python program:

#Prompt the investment Amount
investmentAmount=eval(input("Enter investment amount:"))

#Prompt the annual interest rate
annualinterestrate = eval(input("Enter annual interest rate:"))

#Prompt the number of years
numberofyears = eval(input("Enter number of years:"))

#Calculate the monthly Interest Rate percentage
monthlyInterestRatePer=annualinterestrate/12

#Calculate the monthly Interest Rate
monthlyInterestRate = monthlyInterestRatePer/100

#Calculate the number of months
numberOfMonths = numberofyears * 12

#Calculate the future investment value using the following formula
futureInvestmentValue =investmentAmount * (1+monthlyInterestRate)**numberOfMonths

#Display the Accumulated value
print("Accumulated value is ",int(futureInvestmentValue*100)/100)

Output:

Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Enter investment amount:1000
Enter annual interest rate:4.25
Enter number of years:1
Accumulated value is  1043.33
>>> 

 

0 0

Discussions

Post the discussion to improve the above solution.