-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
355 lines (353 loc) · 13.4 KB
/
index.html
File metadata and controls
355 lines (353 loc) · 13.4 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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Fall 2025 Quiz 2</title>
<style>
/* Default styles provided by pandoc.
** See https://pandoc.org/MANUAL.html#variables-for-html for config info.
*/
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
</style>
<link rel="stylesheet" href="../assets/theme.css" />
<script defer=""
src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
<script>document.addEventListener("DOMContentLoaded", function () {
var mathElements = document.getElementsByClassName("math");
var macros = [];
for (var i = 0; i < mathElements.length; i++) {
var texText = mathElements[i].firstChild;
if (mathElements[i].tagName == "SPAN") {
katex.render(texText.data, mathElements[i], {
displayMode: mathElements[i].classList.contains('display'),
throwOnError: false,
macros: macros,
fleqn: false
});
}}});
</script>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css" />
</head>
<body>
<header id="title-block-header">
<h1 class="title">Fall 2025 Quiz 2</h1>
</header>
<p><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<!-- add after bootstrap.min.css -->
<link rel="stylesheet" href="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.css"/>
<!-- add after bootstrap.min.js or bootstrap.bundle.min.js -->
<script src="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></script></p>
<!-- for difficulty gauges-->
<script src="https://cdn.plot.ly/plotly-2.16.1.min.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-B947E6J6H4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-B947E6J6H4');
</script>
<p><a href="../index.html">← return to practice.dsc10.com</a></p>
<hr />
<p>This quiz was administered in-person. Students were allowed 1
double-sided cheatsheet. Students had <strong>20 minutes</strong> to
work on the quiz.<br><br>This quiz covered Lectures 6-10 of the <a
href="https://dsc-courses.github.io/dsc10-2025-fa">Fall 2025 offering of
DSC 10</a>.</p>
<hr />
<p><strong>Note (groupby / pandas 2.0):</strong> Pandas 2.0+ no longer
silently drops columns that can’t be aggregated after a
<code>groupby</code>, so code written for older pandas may behave
differently or raise errors. In these practice materials we use
<code>.get()</code> to select the column(s) we want after
<code>.groupby(...).mean()</code> (or other aggregations) so that our
solutions run on current pandas. On real exams you will not be penalized
for omitting <code>.get()</code> when the old behavior would have
produced the same answer.</p>
<hr />
<p>The DataFrame <code>chipotle</code> contains information about all
ingredients on the menu at the Chipotle restaurant chain. The DataFrame
is indexed by ingredient <code>"name"</code> (str), and also includes
each ingredient’s <code>"calories"</code> (int), <code>"protein"</code>
content in grams (str), <code>"type"</code> (str: either
<code>"meat"</code>, <code>"base"</code>, or <code>"veggie"</code>), and
<code>"spice_level"</code> (int: either 0, 1, 2, or 3). The
<code>chipotle</code> DataFrame has 30 rows, with the first 5 shown.</p>
<center><img src="https://raw.githubusercontent.com/dsc-courses/practice.dsc10.com/refs/heads/master/assets/images/fa25-quizzes/quiz2df.jpg" width=400></center>
<hr />
<h2 id="problem-1">Problem 1</h2>
<div class="meta">
<p><span class="pill pill-lecture" title="Lecture number(s)">Lecture
8</span></div></p>
<p>For a typical diet, the recommended daily protein intake is 80 g.
Fill in the blanks in the code below to add a new column to
<code>chipotle</code> that contains values 0 to 100 representing the
percentage of the recommended daily protein intake each ingredient
provides.</p>
<pre><code>def clean_protein(grams):
return int(grams.split(" ")[__(a)__]) / __(b)__ * 100
chipotle = chipotle.assign(protein_percent = __(c)__) </code></pre>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading1">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse1" aria-expanded="true" aria-controls="collapse1">
Click to view the solution.
</button>
</h2>
<div id="collapse1" class="accordion-collapse collapse"
aria-labelledby="heading1" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><code>(a)</code>: <code>0</code><br/>
<code>(b)</code>: <code>80</code><br/>
<code>(c)</code>:
<code>chipotle.get("protein").apply(clean_protein)</code></p>
<hr/>
<h5>Difficulty: ⭐️⭐️</h5>
<p>
</p>
<p>The average score on this problem was 88%.</p>
</div>
</div>
</div>
</div>
<hr />
<h2 id="problem-2">Problem 2</h2>
<div class="meta">
<p><span class="pill pill-lecture" title="Lecture number(s)">Lecture
7</span></div></p>
<p>Below is a density histogram showing the distribution of calories for
all 30 ingredients in <code>chipotle</code>.</p>
<center><img src="https://raw.githubusercontent.com/dsc-courses/practice.dsc10.com/refs/heads/master/assets/images/fa25-quizzes/hist.png" width=400></center>
<p><br></p>
<h3 id="problem-2.1">Problem 2.1</h3>
<p>How many ingredients have less than 160 calories?</p>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading2_1">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse2_1" aria-expanded="true" aria-controls="collapse2_1">
Click to view the solution.
</button>
</h2>
<div id="collapse2_1" class="accordion-collapse collapse"
aria-labelledby="heading2_1" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer</strong>: 12</p>
<hr/>
<h5>Difficulty: ⭐️⭐️</h5>
<p>
</p>
<p>The average score on this problem was 83%.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<h3 id="problem-2.2">Problem 2.2</h3>
<p>Suppose we had plotted the histogram with the argument
<code>bins=[120, 160, 190, 210]</code>.</p>
<ol type="i">
<li>How many bars would the histogram have?<br />
</li>
<li>What would the height of the leftmost bar be?</li>
</ol>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading2_2">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse2_2" aria-expanded="true" aria-controls="collapse2_2">
Click to view the solution.
</button>
</h2>
<div id="collapse2_2" class="accordion-collapse collapse"
aria-labelledby="heading2_2" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><code>(i)</code>: 3<br/>
<code>(ii)</code>: 0.01</p>
<hr/>
<h5>Difficulty: ⭐️⭐️⭐️</h5>
<p>
</p>
<p>The average score on this problem was 63%.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<hr />
<h2 id="problem-3">Problem 3</h2>
<div class="meta">
<p><span class="pill pill-lecture" title="Lecture number(s)">Lecture
9</span></div></p>
<p>What is the maximum possible number of rows in the DataFrame that
results from the expression below?</p>
<pre><code>chipotle.groupby(["spice_level", "type"]).mean()</code></pre>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading3">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse3" aria-expanded="true" aria-controls="collapse3">
Click to view the solution.
</button>
</h2>
<div id="collapse3" class="accordion-collapse collapse"
aria-labelledby="heading3" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer</strong>: 12</p>
<hr/>
<h5>Difficulty: ⭐️⭐️⭐️</h5>
<p>
</p>
<p>The average score on this problem was 58%.</p>
</div>
</div>
</div>
</div>
<hr />
<h2 id="problem-4">Problem 4</h2>
<div class="meta">
<p><span class="pill pill-lecture" title="Lecture number(s)">Lecture
9</span></div></p>
<p>Our tutor Noah ate at Chipotle ten times last month (he loves
Chipotle). Each time, Noah only ordered one item, either guacamole,
barbacoa, or steak. The DataFrame below, called
<code>noahs_meals</code>, shows what he ordered.</p>
<center><img src="https://raw.githubusercontent.com/dsc-courses/practice.dsc10.com/refs/heads/master/assets/images/fa25-quizzes/noahsmeals.jpg" width=200 height=400></center>
<p>Suppose we run the code below.</p>
<pre><code>first_five = chipotle.take(np.arange(5))
first_five.merge(noahs_meals, on = "type")</code></pre>
<p>How many rows does the resulting DataFrame contain?</p>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading4">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse4" aria-expanded="true" aria-controls="collapse4">
Click to view the solution.
</button>
</h2>
<div id="collapse4" class="accordion-collapse collapse"
aria-labelledby="heading4" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer</strong>: 17</p>
<hr/>
<h5>Difficulty: ⭐️⭐️⭐️⭐️</h5>
<p>
</p>
<p>The average score on this problem was 42%.</p>
</div>
</div>
</div>
</div>
<hr />
<h2 id="problem-5">Problem 5</h2>
<div class="meta">
<p><span class="pill pill-lecture" title="Lecture number(s)">Lecture
6</span></div></p>
<p><br></p>
<h3 id="problem-5.1">Problem 5.1</h3>
<p>Use the scatterplot of all 30 ingredients to determine how many have
a calorie-to-protein ratio that is at least 5.</p>
<center><img src="https://raw.githubusercontent.com/dsc-courses/practice.dsc10.com/refs/heads/master/assets/images/fa25-quizzes/scat.png" width=300></center>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading5_1">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse5_1" aria-expanded="true" aria-controls="collapse5_1">
Click to view the solution.
</button>
</h2>
<div id="collapse5_1" class="accordion-collapse collapse"
aria-labelledby="heading5_1" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer</strong>: 26</p>
<hr/>
<h5>Difficulty: ⭐️⭐️⭐️</h5>
<p>
</p>
<p>The average score on this problem was 73%.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<h3 id="problem-5.2">Problem 5.2</h3>
<p>Let <code>calories</code> and <code>protein</code> be
<code>numpy</code> arrays containing the calorie and protein amounts, as
ints, for each of the 30 ingredients in <code>chipotle</code>. Fill in
the blanks so that the code below calculates the number of ingredients
with a calorie-to-protein ratio of at least 5.</p>
<pre><code>count = __(a)__
for i in np.arange(__(b)__):
if calories[i] / protein[i] >= 5:
count = __(c)__</code></pre>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading5_2">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse5_2" aria-expanded="true" aria-controls="collapse5_2">
Click to view the solution.
</button>
</h2>
<div id="collapse5_2" class="accordion-collapse collapse"
aria-labelledby="heading5_2" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><code>(a)</code>: <code>0</code><br/>
<code>(b)</code>: <code>len(calories)</code><br/>
<code>(c)</code>: <code>count + 1</code></p>
<hr/>
<h5>Difficulty: ⭐️⭐️</h5>
<p>
</p>
<p>The average score on this problem was 76%.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<hr />
<h2 id="section"><span class="math display"> </span></h2>
<h4
id="feedback-find-an-error-still-confused-have-a-suggestion-let-us-know-here.">👋
Feedback: Find an error? Still confused? Have a suggestion?
<a href="https://forms.gle/WZ71FchnXU1K154d7">Let us know
here</u></a>.</h4>
<hr />
</div>
</div>
</div>
</div>
</div>
</body>
</html>