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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
{
"metadata": {
"name": "Chapter 4"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": "Chapter 4: Basic declarations and expressions"
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Example 4.1, Page number: 71"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Example 4.1.py\n# To perform a simple calculation\n\n\n# Variable declaration\nx = (1 + 2) * 4\n\n# Result\nprint ('1 plus 2 multiplied by 4 gives %d' % x)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "1 plus 2 multiplied by 4 gives 12\n"
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Example 4.2, Page number: 75"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Example 4.2.py\n# To calculate the twice and thrice of 15\n\n\n# Variable declaration\nterm = 3 * 5\nterm_2 = 2 * term\nterm_3 = 3 * term\n\n# Result\nprint ('Twice %d is %d' % (term, term_2))\nprint ('Three times %d is %d' % (term, term_3))",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "Twice 15 is 30\nThree times 15 is 45\n"
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Example 4.3, Page number: 77"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Example 4.3.py\n# To calculate the twice and thrice of 15\n\n\n# Variable declaration\nterm = 3 * 5\nterm_2 = 2 * term\nterm_3 = 3 * term\n\n# Result\nprint ('Twice %d is %d' % (term, term_2))\nprint ('Three times %d is %d' % (term, term_3))",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "Twice 15 is 30\nThree times 15 is 45\n"
}
],
"prompt_number": 3
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Example 4.4, Page number: 79"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Example 4.4.py\n# To determine the value of 1/3\n\n\n# Variable declaration\nanswer = 1/3\n\n# Result\nprint ('The value of 1/3 is %f' % answer)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "The value of 1/3 is 0.000000\n"
}
],
"prompt_number": 4
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Example 4.5, Page number: 80"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Example 4.5.py\n# To determine the value of 2 + 2\n\n\n# Variable declaration\nanswer = 2 + 2\n\n# Result\nprint ('The answer is %d' % answer)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "The answer is 4\n"
}
],
"prompt_number": 5
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Example 4.6, Page number: 80"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Example 4.6.py\n# To determine the integer equivalent of 7.0/22.0 \n\n\n# Variable declaration\nresult = 7.0/22.0\n\n# Result\nprint ('The result is %d' % result)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "The result is 0\n"
}
],
"prompt_number": 6
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Example 4.7, Page number: 82"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Example 4.7.py\n# To determine the reverse of 3 characters\n\n\n# Variable declaration\nchar1 = 'A'\nchar2 = 'B'\nchar3 = 'C'\n\n# Result\nprint ('%c%c%c reversed is %c%c%c' % (char1, char2, char3, char3, char2, char1))",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "ABC reversed is CBA\n"
}
],
"prompt_number": 7
}
],
"metadata": {}
}
]
}
|