Advertisement
aolivens

Python Compunding Investment Calculator

Sep 20th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. #=====================================#
  2. #==============MODULES================#
  3. #=====================================#
  4.  
  5.  
  6.  
  7. #=====================================#
  8. #==============VARIABLES==============#
  9. #=====================================#
  10.  
  11.  
  12.  
  13. #=====================================#
  14. #==============FUNCTIONS==============#
  15. #=====================================#
  16.  
  17. #defines investment algorithm
  18. def invest(principal, rate, period, years):
  19.     for i in range(years):
  20.         apr = (rate / period)
  21.         principal = (principal * (1 + apr))
  22.         if i == (years - 1):
  23.             print "The value in %s years is %s" % (years, principal)
  24.  
  25. #=====================================#
  26. #=============MAIN PROGRAM============#
  27. #=====================================#
  28.  
  29. def main():
  30.     principal = input("Please enter the initial principal: ")
  31.     rate = input("Please enter the annual interest rate: ")
  32.     period = input("Please enter the number of times the interest rate is compounded: ")
  33.     years = input("Please enter the number of years: ")
  34.     invest(principal, rate, period, years)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement