-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz-1081_405899001_基礎程式設計-函式-20200116-2206.xml
492 lines (487 loc) · 14.5 KB
/
quiz-1081_405899001_基礎程式設計-函式-20200116-2206.xml
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/1081_405899001_基礎程式設計的預設/函式</text>
</category>
</question>
<!-- question: 32395 -->
<question type="coderunner">
<name>
<text>呼叫計算應付金額的函式</text>
</name>
<questiontext format="html">
<text><![CDATA[<div class="O1">
<div class="O1">請撰寫一段程式,呼叫上一題的函式,<strong>該函式已寫好不必重寫</strong>,</div>
<div class="O1">請直接呼叫 calculate_total,該函式所需兩個參數以 input 指令取得:</div>
<div class="O1">第一個參數以提示字串 "My price is: " 取得資料需轉為浮點數型別,</div>
<div class="O1">第二個參數以提示字串 "The percentage of my tip is: " 取得資料需轉為整數型別。</div>
<div class="O1">最後顯示 "Total is:" 接著 calculate_total 所傳回的應付金額,如範例所示。</div>
<div class="O1"></div>
</div>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>30.0000000</defaultgrade>
<penalty>0.0000000</penalty>
<hidden>0</hidden>
<coderunnertype>python3</coderunnertype>
<prototypetype>0</prototypetype>
<allornothing>0</allornothing>
<penaltyregime>0</penaltyregime>
<precheck>2</precheck>
<showsource>0</showsource>
<answerboxlines>8</answerboxlines>
<answerboxcolumns>100</answerboxcolumns>
<answerpreload></answerpreload>
<useace></useace>
<resultcolumns></resultcolumns>
<template><![CDATA[__saved_input__ = input
def input(prompt=''):
s = __saved_input__(prompt)
print(s)
return s
def calculate_total(price, percent):
return price+price*percent/100
#my_price=float(input("My price is: "))
#my_tip=int(input("The percentage of my tip is: "))
#print("Total is:",calculate_total(my_price, my_tip))
{{STUDENT_ANSWER}}]]></template>
<iscombinatortemplate></iscombinatortemplate>
<allowmultiplestdins></allowmultiplestdins>
<answer><![CDATA[my_price=float(input("My price is: "))
my_tip=int(input("The percentage of my tip is: "))
print("Total is:",calculate_total(my_price, my_tip))]]></answer>
<validateonsave>1</validateonsave>
<testsplitterre></testsplitterre>
<language></language>
<acelang></acelang>
<sandbox></sandbox>
<grader></grader>
<cputimelimitsecs></cputimelimitsecs>
<memlimitmb></memlimitmb>
<sandboxparams></sandboxparams>
<templateparams></templateparams>
<hoisttemplateparams>0</hoisttemplateparams>
<twigall>0</twigall>
<uiplugin></uiplugin>
<testcases>
<testcase testtype="0" useasexample="1" hiderestiffail="0" mark="1.0000000" >
<testcode>
<text></text>
</testcode>
<stdin>
<text>20
15</text>
</stdin>
<expected>
<text>My price is: 20
The percentage of my tip is: 15
Total is: 23.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>SHOW</text>
</display>
</testcase>
<testcase testtype="0" useasexample="1" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text></text>
</testcode>
<stdin>
<text>100
5</text>
</stdin>
<expected>
<text>My price is: 100
The percentage of my tip is: 5
Total is: 105.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>SHOW</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text></text>
</testcode>
<stdin>
<text>78.5
20</text>
</stdin>
<expected>
<text>My price is: 78.5
The percentage of my tip is: 20
Total is: 94.2</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text></text>
</testcode>
<stdin>
<text>9999990
10</text>
</stdin>
<expected>
<text>My price is: 9999990
The percentage of my tip is: 10
Total is: 10999989.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text></text>
</testcode>
<stdin>
<text>20
100</text>
</stdin>
<expected>
<text>My price is: 20
The percentage of my tip is: 100
Total is: 40.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
</testcases>
</question>
<!-- question: 32393 -->
<question type="coderunner">
<name>
<text>建立計算應付金額的函式</text>
</name>
<questiontext format="html">
<text><![CDATA[<div class="O1">
<div class="O1">請撰寫一個函式,其名稱為 calculate_total,該函式有兩個參數:</div>
<div class="O1">第一個參數名稱為 price ,代表價錢型別為浮點數,</div>
<div class="O1">第二個參數名稱為 percent ,代表小費百分比型別為整數。</div>
<div class="O1">這個函式會計算包含小費的應付金額並<strong>傳回</strong>,其公式為</div>
<div class="O1">total = price + price * percent / 100 </div>
<div class="O1"></div>
</div>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>30.0000000</defaultgrade>
<penalty>0.0000000</penalty>
<hidden>0</hidden>
<coderunnertype>python3</coderunnertype>
<prototypetype>0</prototypetype>
<allornothing>0</allornothing>
<penaltyregime>0</penaltyregime>
<precheck>2</precheck>
<showsource>0</showsource>
<answerboxlines>8</answerboxlines>
<answerboxcolumns>100</answerboxcolumns>
<answerpreload></answerpreload>
<useace></useace>
<resultcolumns></resultcolumns>
<template></template>
<iscombinatortemplate></iscombinatortemplate>
<allowmultiplestdins></allowmultiplestdins>
<answer>def calculate_total(price, percent):
return price+price*percent/100</answer>
<validateonsave>1</validateonsave>
<testsplitterre></testsplitterre>
<language></language>
<acelang></acelang>
<sandbox></sandbox>
<grader></grader>
<cputimelimitsecs></cputimelimitsecs>
<memlimitmb></memlimitmb>
<sandboxparams></sandboxparams>
<templateparams></templateparams>
<hoisttemplateparams>0</hoisttemplateparams>
<twigall>0</twigall>
<uiplugin></uiplugin>
<testcases>
<testcase testtype="0" useasexample="1" hiderestiffail="0" mark="1.0000000" >
<testcode>
<text>print(calculate_total(price=20,percent=15))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>23.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>SHOW</text>
</display>
</testcase>
<testcase testtype="0" useasexample="1" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_total(100,5))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>105.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>SHOW</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_total(price=78.5,percent=20))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>94.2</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_total(9999990,percent=10))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>10999989.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_total(20,100))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>40.0</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
</testcases>
</question>
<!-- question: 32392 -->
<question type="coderunner">
<name>
<text>建立計算身體質量指數(Body Mass Index, BMI)的函式</text>
</name>
<questiontext format="html">
<text><![CDATA[<div class="O1">
<div class="O1">請撰寫一個函式,其名稱為 calculate_bmi,該函式有兩個參數:</div>
<div class="O1">第一個參數名稱為 height ,型別為浮點數,</div>
<div class="O1">第二個參數名稱為 weight ,型別也是浮點數。</div>
<div class="O1">這個函式會計算BMI數值並傳回,其公式為</div>
<div class="O1">bmi = weight / height ** 2 ,所得數值請以round方法四捨五入<strong>取最多小數點2位</strong>。</div>
<div class="O1">這個函式還會再根據下表,以BMI數值落於哪個範圍來傳回對應的文字:</div>
<div class="O1">
<table border="1" style="width: 305px; height: 71px;">
<tbody>
<tr>
<td>BMI數值範圍</td>
<td>顯示文字</td>
</tr>
<tr>
<td>BMI < 18.5</td>
<td>You are underweight.</td>
</tr>
<tr>
<td>18.5 ≤ BMI < 24</td>
<td>You are normal.</td>
</tr>
<tr>
<td>24 <span>≤ BMI < 30</span></td>
<td>You are overweight.</td>
</tr>
<tr>
<td>BMI ≥ 30</td>
<td>You are obese.</td>
</tr>
</tbody>
</table>
</div>
<div class="O1"></div>
<div class="O1"></div>
<div class="O1"></div>
</div>]]></text>
</questiontext>
<generalfeedback format="html">
<text></text>
</generalfeedback>
<defaultgrade>40.0000000</defaultgrade>
<penalty>0.0000000</penalty>
<hidden>0</hidden>
<coderunnertype>python3</coderunnertype>
<prototypetype>0</prototypetype>
<allornothing>0</allornothing>
<penaltyregime>0</penaltyregime>
<precheck>2</precheck>
<showsource>0</showsource>
<answerboxlines>8</answerboxlines>
<answerboxcolumns>100</answerboxcolumns>
<answerpreload></answerpreload>
<useace></useace>
<resultcolumns></resultcolumns>
<template></template>
<iscombinatortemplate></iscombinatortemplate>
<allowmultiplestdins></allowmultiplestdins>
<answer><![CDATA[def calculate_bmi(height,weight):
bmi=round(weight / height ** 2,2)
if bmi < 18.5:
return bmi,"You are underweight."
elif 18.5 <= bmi < 24:
return bmi,"You are normal."
elif 24 <= bmi < 30:
return bmi,"You are overweight."
else:
return bmi,"You are obese."
return bmi,"Out of range."]]></answer>
<validateonsave>1</validateonsave>
<testsplitterre></testsplitterre>
<language></language>
<acelang></acelang>
<sandbox></sandbox>
<grader></grader>
<cputimelimitsecs></cputimelimitsecs>
<memlimitmb></memlimitmb>
<sandboxparams></sandboxparams>
<templateparams></templateparams>
<hoisttemplateparams>0</hoisttemplateparams>
<twigall>0</twigall>
<uiplugin></uiplugin>
<testcases>
<testcase testtype="0" useasexample="1" hiderestiffail="0" mark="1.0000000" >
<testcode>
<text>print(calculate_bmi(height=1.7,weight=57.8))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>(20.0, 'You are normal.')</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>SHOW</text>
</display>
</testcase>
<testcase testtype="0" useasexample="1" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_bmi(1.6,64))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>(25.0, 'You are overweight.')</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>SHOW</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_bmi(height=1.65,weight=49))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>(18.0, 'You are underweight.')</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_bmi(1.8,weight=100))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>(30.86, 'You are obese.')</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
<testcase testtype="0" useasexample="0" hiderestiffail="1" mark="1.0000000" >
<testcode>
<text>print(calculate_bmi(1.75,73.5))</text>
</testcode>
<stdin>
<text></text>
</stdin>
<expected>
<text>(24.0, 'You are overweight.')</text>
</expected>
<extra>
<text></text>
</extra>
<display>
<text>HIDE</text>
</display>
</testcase>
</testcases>
</question>
</quiz>