1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
{
"metadata": {
"name": "",
"signature": "sha256:315aef45dcd0f156b4319ee68cddb70a9a8edfeb1c485c709f025d64bf2af90b"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"8 Discrete numeric functions and generating functions"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 01:Page 368"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"Suppose we deposit $100 in a savings account at an interest rate of 7 percent per year, compounded annually\"\n",
"principal=100\n",
"rate_of_interest=7\n",
"def amount(r): # r represents the number of years\n",
" 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\n",
" return a\n",
"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\n",
"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\n",
"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\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Suppose we deposit $100 in a savings account at an interest rate of 7 percent per year, compounded annually\n",
"At the end of the first year, the total amount in the account is $ 107.0\n",
"At the end of the second year, the total amount in the account is $ 114.49\n",
"At the end of the third year, the total amount in the account is $ 122.5\n"
]
}
],
"prompt_number": 1
}
],
"metadata": {}
}
]
}
|