Calculating compound interest. : For « Language Basics « Python






Calculating compound interest.

Calculating compound interest.


principal = 1000.0   # starting principal
rate = .05           # interest rate

print "Year %21s" % "Amount on deposit"

for year in range( 1, 11 ):
   amount = principal * ( 1.0 + rate ) ** year
   print "%4d%21.2f" % ( year, amount )



           
       








Related examples in the same category

1.Dictionary for loopDictionary for loop
2.For loop demoFor loop demo
3.for with else for with else
4.Nested if demoNested if demo