-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.html
More file actions
368 lines (343 loc) · 14.7 KB
/
Copy pathindex2.html
File metadata and controls
368 lines (343 loc) · 14.7 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"></html>
<head>
<title>Python 2 Term Quiz</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en" />
<meta name="robots" content="index,follow" />
<link rel="stylesheet" type="text/css" href="./resources/css.css" media="screen" />
<link rel="stylesheet" type="text/css" href="./resources/code.css" media="screen, print" />
<link href='./resources/print_stylesheet.css' rel='stylesheet' type='text/css' media='print' />
<script src="./resources/AC_QuickTime.js" language="javascript" type="text/javascript"> </script>
<script src="./resources/common.js" language="javascript" type="text/javascript"> </script>
<script src="./jsFiles/unitData.js" language="javascript" type="text/javascript"> </script>
<script src="./jsFiles/exercises-4.js" language="javascript" type="text/javascript"> </script>
<script type="text/javascript" src="./resources/shCore.js"></script>
<script type="text/javascript" src="./resources/shBrushJScript.js"></script>
<script type="text/javascript" src="./resources/shBrushPlain.js"></script>
<script type="text/javascript" src="./resources/shBrushXml.js"></script>
<link type="text/css" rel="stylesheet" href="./resources/shCore.css"/>
<link type="text/css" rel="stylesheet" href="./resources/shThemeDefault.css"/>
<script type="text/javascript">
SyntaxHighlighter.config.clipboardSwf = './resources/clipboard.swf';
SyntaxHighlighter.all();
</script>
</head>
<body>
<div id="center">
<div id="border">
<div id="logo" class="noprint">
Introduction to Programming - Python<br>
Author: <b>Lucy</b>
</div>
<div style="font:1.3em geneva,arial,sans-serif;" class="noview">
Introduction to Python 2
<hr />
</div>
<div class="noprint">
<p class="heading">
<a style="color:#999;font-weight:bold;" href="#" /><img src="./resources/home_24.png" />Python</a>
<img src="./resources/arrow_right_small.png" />Introduction to Python <hr />
</p>
</div>
<div id="main">
<h1>Quiz : Fundemental Python 2<hr /></h1></div>
<div class="noprint">
<h2>Part 1: Multiple Choice</h2>
<ol>
<li>What is the value of the following expression?</li>
<blockquote>
<code>print(25/5)<br></code>
</blockquote><br>
<form id = "form1" action="">
<input type="radio" name="1" value="a">a. 5.0<br>
<input type="radio" name="1" value="b">b. 5<br>
<input type="radio" name="1" value="c">c. error<br>
<br>
<input type="button" onclick="myFunc1()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput1" size="50"></div>
</form><br>
<li>What is the value of the following expression?</li>
<blockquote>
<code>print(-28//5)<br></code>
</blockquote><br>
<form id = "form2" action="">
<input type="radio" name="1" value="a">a. -5<br>
<input type="radio" name="1" value="b">b. 5<br>
<input type="radio" name="1" value="c">c. -6<br>
<input type="radio" name="1" value="d">d. 6<br>
<br>
<input type="button" onclick="myFunc2()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput2" size="50"></div>
</form><br>
<li>What is the output of the following code?</li>
<blockquote>
<code>def output(**args):<br> for i in args:<br> print(i)<br>output(name = "Alice", id = 007)<br></code>
</blockquote><br>
<form id = "form3" action="">
<input type="radio" name="1" value="a">a. Alice<br> 007<br>
<input type="radio" name="1" value="b">b. ('name', 'Alice')<br> ('id', 007)<br>
<input type="radio" name="1" value="c">c. name<br> id<br>
<input type="radio" name="1" value="d">d. TypeError<br>
<br>
<input type="button" onclick="myFunc3()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput3" size="50"></div>
</form><br>
<li>What is the output of the following code?</li>
<blockquote>
<code>def output(*args):<br> for i in args:<br> print(i)<br>output(name = "Alice", id = 007)<br></code>
</blockquote><br>
<form id = "form3" action="">
<input type="radio" name="1" value="a">a. Alice<br> 007<br>
<input type="radio" name="1" value="b">b. ('name', 'Alice')<br> ('id', 007)<br>
<input type="radio" name="1" value="c">c. name<br> id<br>
<input type="radio" name="1" value="d">d. TypeError<br>
<br>
<input type="button" onclick="myFunc3_1()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput3_1" size="50"></div>
</form><br>
<li>What is the output of the add() function call?</li>
<blockquote>
<code>def add(x, y):<br> return x+3, y+5<br>output = add(1, 2)<br>print(output)
<br></code>
</blockquote><br>
<form id = "form4" action="">
<input type="radio" name="1" value="a">a. 11<br>
<input type="radio" name="1" value="b">b. 4<br>
<input type="radio" name="1" value="c">c. Syntax Error<br>
<input type="radio" name="1" value="d">d. (4, 7)<br>
<br>
<input type="button" onclick="myFunc4()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput4" size="50"></div>
</form><br>
<li>What is the output of the following code?</li>
<blockquote>
<code>def first(a, b):<br>
def second(c, d):<br>
return c + d<br>
return second(a, b)<br>
return a<br>
res = first(10, 20)<br>
print(res)
<br></code>
</blockquote><br>
<form id = "form5" action="">
<input type="radio" name="1" value="a">a. 10<br>
<input type="radio" name="1" value="b">b. 30<br>
<input type="radio" name="1" value="c">c. 30 10<br>
<input type="radio" name="1" value="d">d. (30, 10)<br>
<input type="radio" name="1" value="d">e. Syntax Error<br>
<br>
<input type="button" onclick="myFunc5()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput5" size="50"></div>
</form><br>
<li>What is the output of the following code?</li>
<blockquote>
<code>myTuple = (10, 20, 30, 40, 50)<br>
myTuple[1] = 25<br>
print(myTuple)
<br></code>
</blockquote><br>
<form id = "form6" action="">
<input type="radio" name="1" value="a">a. (10, 25, 30, 40, 50)<br>
<input type="radio" name="1" value="b">b. (25, 20, 30, 40, 50)<br>
<input type="radio" name="1" value="c">c. (10, 20, 30, 40, 50)<br>
<input type="radio" name="1" value="d">d. TypeError<br>
<br>
<input type="button" onclick="myFunc6()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput6" size="50"></div>
</form><br>
<li>What is the output of the following code?</li>
<blockquote>
<code>set1 = {10, 20, 30, 40}<br>
set2 = {'10', 50, '60', 70}<br>
set3 = set1.union(set2)<br>
print(set3)
<br></code>
</blockquote><br>
<form id = "form7" action="">
<input type="radio" name="1" value="a">a. {40, 50, 20, 30, 10, 60, 70}<br>
<input type="radio" name="1" value="b">b. {40, 50, 20, 30, 10, 60, '10', 70}<br>
<input type="radio" name="1" value="c">c. {40, 50, 20, 30, '10', 60, 70}<br>
<input type="radio" name="1" value="d">d. SyntaxError<br>
<br>
<input type="button" onclick="myFunc7()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput7" size="50"></div>
</form><br>
<li>What is the output of the following code?</li>
<blockquote>
<code>shapeSet = {'triangle','circle','hexagon','pantagon'}<br>
print(shapeSet[1])
<br></code>
</blockquote><br>
<form id = "form8" action="">
<input type="radio" name="1" value="a">a. circle<br>
<input type="radio" name="1" value="b">b. triangle<br>
<input type="radio" name="1" value="c">c. 'circle'<br>
<input type="radio" name="1" value="d">d. SyntaxError<br>
<br>
<input type="button" onclick="myFunc8()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput8" size="50"></div>
</form><br>
<li>Which is true for Python function?</li>
<form id = "form9" action="">
<input type="checkbox" name="1" value="a">a. A function can return only a single value<br>
<input type="checkbox" name="1" value="b">b. A function can take an unlimited number of arguments<br>
<input type="checkbox" name="1" value="c">c. A function can return multiple values<br>
<input type="checkbox" name="1" value="d">d. A function doesn't return anythin unless add a return statement<br>
<input type="checkbox" name="1" value="e">e. A function is a code block that only executes when it is called<br>
<input type="checkbox" name="1" value="f">f. A function always returns a value<br>
<input type="checkbox" name="1" value="g">g. A function can be reused in a program<br>
<input type="checkbox" name="1" value="h">h. Python doesn't support nested function<br>
<br>
<input type="button" onclick="myFunc9()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput9" size="50"></div>
</form><br>
<li>Which is true for Python tuple?</li>
<form id = "form10" action="">
<input type="checkbox" name="1" value="a">a. A tuple maintains the order of items<br>
<input type="checkbox" name="1" value="b">b. A tuple is unordered<br>
<input type="checkbox" name="1" value="c">c. We cannot change the tuple once created<br>
<input type="checkbox" name="1" value="d">d. We cannot remove items from the tuple<br>
<input type="checkbox" name="1" value="e">e. We cannot delete the tuple<br>
<input type="checkbox" name="1" value="f">f. We cannot update items of the tuple<br>
<input type="checkbox" name="1" value="g">g. A tuple can be created without using parentheses<br>
<br>
<input type="button" onclick="myFunc10()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput10" size="50"></div>
</form><br>
<li>Which is true for Python set?</li>
<form id = "form11" action="">
<input type="checkbox" name="1" value="a">a. Set is unordered<br>
<input type="checkbox" name="1" value="b">b. Set does not allow duplicate<br>
<input type="checkbox" name="1" value="c">c. Set is around by curly braces<br>
<input type="checkbox" name="1" value="d">d. Set is immutable<br>
<input type="checkbox" name="1" value="e">e. Set supports indexing<br>
<br>
<input type="button" onclick="myFunc11()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput11" size="50"></div>
</form><br>
</ol></div>
<div class="noprint">
<h2>Part 2: Complete input field</h2>
<ol>
<li>What is the output of the following function call?</li>
<blockquote>
<code>def first(a, b):<br>
def second(c, d):<br>
return c + d<br>
return second(a, b)<br>
res = first(10, 20)<br>
print(res)<br>
</code>
</blockquote><br>
<input type="text" id="input2_1" size="50" required><span id="sp21" class="tick"></span><br>
<input type="button" onclick="myFunc2_1()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput2_1" size="50"></div>
<br>
<li>What is the output of the code?</li>
<blockquote>
<code>
x = [1,2]<br>
y = x<br>
y += [3,4]<br>
print(x, end=' ')<br>
print(y)<br>
</code>
</blockquote>
<input type="text" id="input2_2" size="50" required><span id="sp22" class="tick"></span><br>
<div><input type="button" onclick="myFunc2_2()" value="SUBMIT"></div><br>
<div class="divOutput" id="divOutput2_2" size="50"></div>
<!--<div>
<ul>
<li>Sample Output:</li><br>
</ul>
<div class="blackGreen" style="background-color:#444;">
<p style="color:#22FF22;">Enter the first number: 20<br>Enter the second number: 30<br>The sum is 50</p>
</div>
</div>--><br>
<li>What is the output of the following code?</li>
<blockquote>
<code>
myTuple = (10, 20, 30, 40, 50)<br>
</code>
</blockquote>
<code>print(myTuple[-2])</code><br>
<input type="text" id="input2_3_1" size="50" required><span id="sp231" class="tick"></span><br>
<input type="button" onclick="myFunc2_3_1()" value="SUBMIT">
<br><br>
<code>print(myTuple[-4:-1])</code><br>
<input type="text" id="input2_3_2" size="50" required><span id="sp232" class="tick"></span><br>
<input type="button" onclick="myFunc2_3_1()" value="SUBMIT">
<br><br>
<blockquote>
<code>
numTuple = (0, 10, 20, 30, 40, 50, 60, 70, 80)<br>
</code>
</blockquote>
<code>print(numTuple[2:5], numTuple[:4], numTuple[3:])</code><br>
<input type="text" id="input2_3_3" size="50" required><span id="sp233" class="tick"></span><br>
<input type="button" onclick="myFunc2_3_1()" value="SUBMIT">
<br><br>
<div class="divOutput" id="divOutput2_3_1" size="50"></div>
</ol>
</div>
<div class="noprint">
<h2>Part 3: Coding</h2>
<h3>Narcissistic Number</h3>
<ul>
<li>What is <b>Narcissistic Number</b>?</li>
<li>Click <a href='http://ey.westside66.org/32-math-minute-narcissistic-numbers/'>here</a> to learn more about <strong>Narcissistic Number</strong>!</li>
<li>A <strong>Narcissistic Number</strong> is a number that is the sum of its own digits each raised to the power of the number of digits.</li>
<li>How to determine if a number is a <strong>Narcissistic Number</strong>?</li>
<li>(Optional) Can you print all <strong>Narcissistic Number</strong> in the range of 1 to 999?</li>
</ul><br><br>
<div style="text-align: center;">
<img src="resources/nar1.jpg" alt="" height="600" width="900" />
</div>
</div>
<div class="noprint">
<h2>Part 4: File I/O</h2>
<h3>Alice's Adventures in Wonderland</h3>
<ul>
<li>Click <a href='http://www.umich.edu/~umfandsf/other/ebooks/alice30.txt'>here</a> to download the text file to your local computer.</li>
<li>Write a program to count how many times the "<strong>March Hare</strong>" appears.</li>
<li>Generate a custom <strong>WordCloud</strong> image.</li>
</ul>
<div style="text-align: center;">
<img src="resources/alice.png" alt="" height="450" width="600" />
</div>
</div>
<p><br /></p>
<div>
<p>
<!-- <a style="color:#999;font-weight:bold;" href="excutable.html">Link: make your .exe</a><hr /> -->
</p>
</div>
<p><br /><br /><br /></p>
<div id="footer" class="noprint">
<p class="footer">
<input type=button value="Back" onClick="history.go(-1)">
<a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.1</a>
| <a href="http://jigsaw.w3.org/css-validator/">Valid CSS</a>
| Design by <a href=""><b>Lucy Lin</b></a>
</p>
</div>
</div>
</div>
</body>
</html>