Python Programming – John Zelle / Chapter 2 Exercise 5

Modify the futval.py program (Section 2.7) so that the number of years for the investment is also a user input. Make sure to change the final message so reflect the correct number of years.

#Chapter 2 Exercise 5 def main(): print("This program calculates the future value of an investment.") principal = eval(input("Enter the initial principal: ")) apr = eval(input("Enter the annual interest rate: ")) yr = eval(input("Enter the number of years: ")) for i in range (yr): principal = principal * (1 + apr) print("The value in", yr , "years is $""{0:.2f}" .format(principal)) main()

Nice post!