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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
{
"metadata": {
"name": "Chapter XIII"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 13: The preprocessor"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Program 13.1, Page number: 300"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"global YES\n",
"global NO\n",
"YES=1\n",
"NO=0\n",
"\n",
"\n",
"def isEven(number):\n",
" global YES\n",
" global NO\n",
"\n",
" if(number%2==0):\n",
" answer=YES\n",
" else:\n",
" answer=NO\n",
"\n",
" return answer\n",
"\n",
"def main():\n",
" global YES\n",
" global NO\n",
"\n",
" #Calculation/Result\n",
" if(isEven(17)==YES):\n",
" print(\"YES\")\n",
" else:\n",
" print(\"NO\")\n",
"\n",
" \n",
" if(isEven(20)==YES):\n",
" print(\"YES\")\n",
" else:\n",
" print(\"NO\")\n",
"\n",
"\n",
"if __name__=='__main__':\n",
" main()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"NO\n",
"YES\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Program 13.2, Page number: 302"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"global PI\n",
"PI= 3.141592654\n",
"\n",
"\n",
"def area(r):\n",
" global PI\n",
" return (PI*r*r)\n",
"\n",
"def circumference(r):\n",
" global PI\n",
" return (2*PI*r)\n",
"\n",
"def volume(r):\n",
" global PI\n",
" return (1.33 * PI*r*r*r)\n",
" \n",
"\n",
"def main():\n",
" print(\"radius=1 {0:5} {1:5} {2:5}\".format(area(1),circumference(1),volume(1)))\n",
" print(\"radius=4.98 {0:5} {1:5} {2:5}\".format(area(4.98),circumference(4.98),volume(4.98)))\n",
"\n",
"\n",
"if __name__=='__main__':\n",
" main()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"radius=1 3.141592654 6.283185308 4.17831822982\n",
"radius=4.98 77.9127544563 31.2902628338 516.047337866\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Program 13.3, Page number: 314"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"global QUARTS_PER_LITER\n",
"QUARTS_PER_LITER=1.05687\n",
"\n",
"def main():\n",
" global QUARTS_PER_LITER #Global Reference\n",
"\n",
" print(\"***Liters to galons***\")\n",
" print(\"Enter the number of Litres\")\n",
" liters=12 #liters=raw_input()\n",
"\n",
" gallons=float(liters)*QUARTS_PER_LITER/4.0 #calculation\n",
"\n",
" print(\"{0} Liters = {1} gallons\".format(liters,gallons))\n",
"\n",
"if __name__=='__main__':\n",
" main()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"***Liters to galons***\n",
"Enter the number of Litres\n",
"12 Liters = 3.17061 gallons\n"
]
}
],
"prompt_number": 3
}
],
"metadata": {}
}
]
}
|