← return to practice.dsc10.com
This quiz was administered in-person. It was closed-book and
closed-note; students were not allowed to use the DSC
10 Reference Sheet. Students had 20 minutes to work on
the quiz.
This quiz covered Lectures 7-10 of the Spring 2026 offering
of DSC 10.
Note (groupby / pandas 2.0): Pandas 2.0+ no longer
silently drops columns that can’t be aggregated after a
groupby, so code written for older pandas may behave
differently or raise errors. In these practice materials we use
.get() to select the column(s) we want after
.groupby(...).mean() (or other aggregations) so that our
solutions run on current pandas. On real exams you will not be penalized
for omitting .get() when the old behavior would have
produced the same answer.
Clash Royale is a mobile game where players build decks of cards and use the abilities provided by those cards to destroy their opponent’s defenses.
The cards DataFrame describes the cards in the game. It
is indexed by card "name" and has columns:
"damage" (int): amount of damage dealt by
the card"type" (str): card type, either
"spell", "troop", or
"building""rarity" (str): card rarity, either
"common", "rare", or "epic""arena_unlocked" (int): a number 1 through
14 representing the stage of the game in which the card can be usedcards has 40 rows and is
sorted in ascending order of
"arena_unlocked". The first figure below shows the first
six rows of cards, and the second figure shows the
distribution of "arena_unlocked" over all 40 rows.


Assume that we have already run import babypandas as bpd
and import numpy as np.
Using the density histogram above, how many cards have an
"arena_unlocked" that is strictly less than
6?
Answer: 24
The average score on this problem was 62%.
Give a mathematical expression that evaluates to the exact height of the rightmost bin in the histogram above. You do not need to simplify.
Answer: \frac{1 - \left(0.10\cdot(4-1) + 0.15\cdot(6-4) + 0.08\cdot(9-6)\right)}{15 - 9} = \frac{0.16}{6} = \frac{0.08}{3}
The average score on this problem was 61%.
Assume you also have access to another DataFrame, bonus,
shown in full below. Determine the number of rows in
cards.merge(bonus, on="arena_unlocked").

Answer: 7
The average score on this problem was 38%.
Fill in the blanks to add a new column "unlock"
containing strings of the form "Arena k" where
k is the corresponding value in the
"arena_unlocked" column (e.g. 3 \rightarrow "Arena 3").
def make_unlock(arena_num):
return __(a)__
cards = cards.assign(unlock=__(b)__)
(a): "Arena" + str(arena_num)
(b):
cards.get("arena_unlocked").apply(make_unlock)
The average score on this problem was 67%.
Fill in the blanks below so the code prints the "type"
and "rarity" combination for which the average
"damage" is greatest.
grouped = (cards.groupby(__(a)__).mean().reset_index()
.sort_values(by=__(b)__, ascending=__(c)__))
print("type", grouped.get("type").iloc[0])
print("rarity", grouped.get("rarity").iloc[0])
(a): ["type", "rarity"]
(b): "damage"
(c): False
The average score on this problem was 88%.
Suppose d is an array of length 40, containing integers
representing the damage done by each card in cards.
Likewise, suppose c is an array of length 40, containing
integers representing the cost of each card in cards. Fill
in the blanks below to calculate the number of cards, n,
for which the damage is more than 400
times the cost.
n = __(a)__
for i in np.arange(__(b)__):
if d[i] > 400 * c[i]:
n = __(c)__
(a): 0
(b): len(d) or len(c) or
40
(c): n + 1
The average score on this problem was 66%.