# 8 Discrete numeric functions and generating functions¶

## Example 01:Page 368¶

In [1]:
print "Suppose we deposit $100 in a savings account at an interest rate of 7 percent per year, compounded annually" principal=100 rate_of_interest=7 def amount(r): # r represents the number of years a=principal*pow(1.07,r) # Since the formula for compound interest is 100*(1+(rate_of_interest/100)) and rate_of_interest here is 7 return a print "At the end of the first year, the total amount in the account is$",amount(1) #Since we calculate the amount after 1 year, here r is 1
print "At the end of the second year, the total amount in the account is $",amount(2) #Since we calculate the amount after 2 years, here r is 2 print "At the end of the third year, the total amount in the account is$",round(amount(3),2) #Since we calculate the amount after 3 years, here r is 3

Suppose we deposit $100 in a savings account at an interest rate of 7 percent per year, compounded annually At the end of the first year, the total amount in the account is$ 107.0
At the end of the second year, the total amount in the account is $114.49 At the end of the third year, the total amount in the account is$ 122.5