[Tutor] Concerning Programming Exercise #6 of Chapter 2 of Python Programming John Zelle Textbook

Donna Belle Ibarra dbibarra at ucdavis.edu
Tue Jan 20 19:04:17 CET 2009


Hi! I need help with program exericse #6 entitled "Futval.py" which is a
program that computes the value of an investment carried 10 years into the
future.

This is the coding I have.. yet it does not seem to spit out the correct
numbers (Am I using an incorrect equation?)

*def main():
    print "This program calculates the future value"
    print "of a 10-year investment."

    principal = input("Enter the amount invested each year: ")
    apr = input("Enter the annual interest rate: ")
    years = input("Enter the number of years: ")

    for i in range (1, years + 1):
        principal = principal * (1 + apr)**i
        print "The value in", i, " years is:", principal

main()*

The output is suppose to appear like this:

This program calculates the future value of a 10-year investment.
Enter the amount invested each year: 100.00
Enter the annual interst rate: 0.05
Enter the number of years: 10
The value in 1 years is 105.0
The value in 2 years is 215.25
The value in 3 years is 331.0125
The value in 4 years is 452.563125

And so on..

^Please help me!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090120/af068383/attachment.htm>


More information about the Tutor mailing list