Spring 2025 Quiz 1

← return to practice.dsc10.com


This quiz was administered in-person. It was closed-book; students were not allowed to use the DSC 10 Reference Sheet but were allowed a double-sided sheet of handwritten notes. Students had 20 minutes to work on the quiz.

This quiz covered Lectures 1-5 of the Spring 2025 offering of DSC 10.

⚠️ PDF version available here .


That's the end of the quiz.

In the video game Minecraft, players mine raw materials, craft various tools, and build structures such as houses.
A player named Steve has several storage chests in which he keeps items he owns. Each chest has a different descriptive name and contains items of various types. For example, one of Steve’s chests is called "Food" and it contains 12 "Golden Carrot" and 8 "Rabbit Stew" items.

The items DataFrame contains all the items Steve has in his chests. It is indexed by "Item" (name of the item). The columns are "Quantity" (number of such items) and "Chest" (name of the chest where all such items are stored). The first few rows are shown below, though items has more rows than pictured.


Problem 1

Lecture 5

Fill in the blanks so the expression below evaluates to the name of the chest that contains the most distinct items.


    (items.groupby(___(a)___).___(b)___
          .sort_values(by="Quantity", ascending=___(c)___).___(d)___)

Answer:

  • (a) "Chest"
  • (b) count()
  • (c) False
  • (d) index[0]

Solution:

We first use groupby("Chest") to group items that are stored in the same chest. Next, we use .count() to count the number of distinct items in each chest. Each row now represents a single chest and the number of distinct items within it. The "Quantity" column contains the number of distinct items in each chest, while the index contains the chest names. We then use .sort_values(by="Quantity", ascending=False) to sort the chests in descending order by their number of distinct items. Because we sorted by descending order, the chest with the most distinct items is the first row. This is why .index[0] retrieves our desired answer. Sorting by ascending order and selecting the last row (.index[-1]) would’ve worked as well.


  1. Difficulty: ⭐️⭐️

    The average score on this problem was 89%.


  2. Difficulty: ⭐️⭐️⭐️⭐️

    The average score on this problem was 39%.


  3. Difficulty: ⭐️⭐️

    The average score on this problem was 86%.


  4. Difficulty: ⭐️⭐️⭐️

    The average score on this problem was 67%.


Problem 2

Lecture 5

Steve wants to build a village where each house is built using a different "Item" from the "Materials" chest (e.g., a cobblestone house, a wood house, a brick house, etc). Assuming that each house requires at least 416 blocks of a single material, fill in the blanks so that the expression below evaluates to the number of houses that Steve’s village will have.

    items[(___(a)___) & (___(b)___)].___(c)___

Answer:

  • (a) items.get("Chest") == "Materials"
  • (b) items.get("Quantity") >= 416
  • (c) shape[0]

Solution:

We first use items.get("Chest") == "Materials" to identify the rows corresponding to items stored in the "Materials" chest. Next, we use items.get("Quantity") >= 416 to identify items with at least 416 blocks, since each house requires at least 416 blocks of a single material. We combine these two conditions using & to filter the DataFrame to only include items that satisfy both conditions. Finally, .shape[0] returns the number of rows in the filtered DataFrame, giving us the total number of houses in Steve’s village. Note that answer (a) and (b) may be swapped.


  1. Difficulty: ⭐️⭐️⭐️

    The average score on this problem was 71%.


  2. Difficulty: ⭐️⭐️⭐️

    The average score on this problem was 71%.


  3. Difficulty: ⭐️⭐️⭐️⭐️⭐️

    The average score on this problem was 27%.


Problem 3

Lecture 5

Which of the following expressions evaluates to the number of "Emerald"s in Steve’s chests? Select all that apply.

Answer:

Option 1 and Option 4

Solution:

Option 1 is correct because "Item" is the index of our DataFrame, so .loc["Emerald"] retrieves the quantity corresponding to the "Emerald" index label. Option 2 is incorrect because "Item" is the index, not a column. Therefore, items.get("Item") would error. Option 3 is incorrect because sorting by "Quantity" in ascending order and selecting .iloc[0] retrieves the smallest quantity in the DataFrame, which is not necessarily the quantity of Emeralds. Option 4 is correct because items.index == "Emerald" filters the DataFrame to the singular row corresponding to Emeralds, and .get("Quantity").iloc[0] retrieves the quantity from that row.


Difficulty: ⭐️⭐️

The average score on this problem was 78%.


Problem 4

Lecture 2

In early versions of Minecraft, players reported sighting a hazy figure with glowing eyes, who they nicknamed Herobrine. Examine the mysterious code that Herobrine left behind and determine the output. Write your answer exactly how the output would appear in Python. Do it wrong and your diamonds will disappear.

    curse = 3 + 4 * 2 ** 2 - 6/3
    curse

Answer: 17.0

Solution

Following the order of operations in Python, we start with 2 ** 2, which gives us 4. Our expression is now 3 + 4 * 4 - 6/3. We can now focus on multiplication and division. 4 * 4 is 16, and 6/3 is 2. Our expression is now 3 + 16 - 2. Working from right to left, we get our final answer of 17.


Difficulty: ⭐️⭐️

The average score on this problem was 85%.


Problem 5

Lecture 3

Below is the opening line from the legendary Minecraft parody song

Revenge:


    line = "Creeper aww man"

You want to create an echo effect to produce the following string:

    "Creeper Creeper Creeper aww man"

Which of the following code snippets produces this output? Select all that apply.

Answer:

Option 1 and Option 3

Solution:

Option 1 is correct because line.split(" ") separates the string into individual words, and (words[0] + " ") * 3 repeats "Creeper " three times before concatenating the remaining words. Option 2 is incorrect because line * 3 repeats concatenation of the entire string three times, producing "Creeper aww manCreeper aww manCreeper aww man". Option 3 is correct because .replace("Creeper", "Creeper Creeper Creeper") replaces the original occurrence of "Creeper" with three repetitions, which is what we want. Option 4 is incorrect because words[0] * 3 + words[1] creates "CreeperCreeperCreeperaww", and " ".join(...) inserts spaces between each character, producing "C r e e p e r C r e e p e r C r e e p e r a w w".


Difficulty: ⭐️

The average score on this problem was 93%.


👋 Feedback: Find an error? Still confused? Have a suggestion? Let us know here.