Fall 2023 Quiz 1

← 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 1-4 of the Fall 2023 offering of DSC 10.

⚠️ PDF version available here .


That's the end of the quiz.

Problem 1

Lecture 2

After a trip to the zoo, Anthony wrote the following block of code.

zebra = 5
lion = 4
cow = 1
zebra = zebra * 2
lion = abs(cow - lion)
zebra = zebra + lion ** 2
cow = (zebra + lion) / 2 * lion

After running the above block of code, what is the value of cow?

Answer: 33.0

zebra becomes 5, then lion becomes 3, then zebra becomes 19, then finally cow = 33.0 since integer division produces a float.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 60%.


Problem 2

Lecture 3

Consider the following four assignment statements.

bass = "5"
tuna = 2
sword = ["4.0", 5, 12.5, -10, "2023"]
gold = [4, "6", "CSE", "doc"]


Problem 2.1

What is the value of the expression bass * tuna?

Answer: "55"

Multiplying a string produces a larger string containing that many copies of the original string.


Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 48%.


Problem 2.2

Which of the following expressions results in an error?

Answer: int(sword[0])

“44.0” isn’t directly convertible to an int (it would be a float) so the conversion fails.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 51%.


Problem 2.3

Which of the following expressions evaluates to "DSC10"?

Answer: gold[3].replace("o", "s").upper() + str(gold[0] + int(gold[1]))

We would want upper to produce “DSC” instead of title which would product “Dsc”, and gold[0] + int(gold[1]) is the only expression that would produce 10, which we then convert to a string.


Difficulty: ⭐️

The average score on this problem was 92%.



Problem 3

Lecture 3

Consider the following assignment statement.

puffin = np.array([5, 9, 13, 17, 21])


Problem 3.1

Provide arguments to call np.arange with so that the array penguin is identical to the array puffin.

penguin = np.arange(____)

Answer: We need to provide np.arange with three arguments: 5, anything in (21, 25], 4. For instance, something like penguin = np.arange(5, 25, 4) would work.


Difficulty: ⭐️

The average score on this problem was 90%.


Problem 3.2

Fill in the blanks so that the array parrot is also identical to the array puffin.
Hint: Start by choosing y so that parrot has length 5.

parrot = __(x)__ * np.arange(0, __(y)__, 2) + __(z)__

Answer:

  • x: 2
  • y: anything in (8, 10]
  • z: 5

Let’s work from the inside out. First inside the arange, we need length 5 so anywhere between 8-10 results in 5 entries in the array. Next, we need to multiply by 2 since the difference between elements in the final array should be 4, while the arange difference is 2. Finally, add 5 to make the first element from 0 to 5, and the other elements follow suit.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 74%.



Problem 4

Lecture 4

Suppose students is a DataFrame of all students who took DSC 10 last quarter. students has one row per student, where:


Problem 4.1

What type is students.get("Overall")? If this expression errors, select “this errors."

Answer: Series

.get() without brackets in the argument returns a series.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 73%.


Problem 4.2

What type is students.get("PID")? If this expression errors, select “this errors."

Answer: this errors

“PID” is not a column, so it errors.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 67%.


Vanessa is one student who took DSC 10 last quarter. Her PID is A12345678, she earned the sixth-highest overall percentage grade in the class, and her favorite animal is the giraffe.


Problem 4.3

Supposing that students is already sorted by "Overall" in descending order, fill in the blanks so that animal_one and animal_two both evaluate to "giraffe".

animal_one = students.get(__(x)__).loc[__(y)__]
animal_two = students.get(__(x)__).iloc[__(z)__]

Answer:

  • x: "Animal"
  • y: "A12345678"
  • z: 5
  1. is the most obvious since we need the Animal of the student. (y) should be the PID of the student we want since .loc will search the index, in this case the PIDs, for the argument we provide. (z) should be the position of the student in the dataframe since .iloc looks for that, and since we know the array is sorted in descending order, the index 5 should get us position 6.

Difficulty: ⭐️⭐️⭐️

The average score on this problem was 69%.


Problem 4.4

If students wasn’t already sorted by "Overall" in descending order, which of your answers would need to change?

Answer: z only

  1. is the only one that relies on the sorting of the dataframe.

Difficulty: ⭐️⭐️

The average score on this problem was 82%.



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