← 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 2024 offering of
DSC 10.
What does the following expression evaluate to? Write your answer exactly how the output would appear in Python.
5 * (4 ** 3 - 40) / (2 * 8) ** .5 + 10 / 3 + 2 * (5 / 6 - 1 / 2)
Answer: 34.0
The average score on this problem was 61%.
Select all the answer choices below that correspond to valid assignment statements. For the selected choice(s) only, write the value of the variable.
"seal" = abs(-7) + round(23.442, 1)
whale = max(round(17.82), 5, -20)
shark = abs(max(4, 3, min(10, 5.5, 11)), 100, 30)
squid = "error" + "?" * 4
Answer:
18
"error????"
The average score on this problem was 78%.
Suppose that weights
is an array containing the weights,
in kilograms, of several leopard sharks living in La Jolla Cove. Several
leopard sharks represented in weights
weigh more than 10
kilograms.
Suppose that we have imported a module called sharkpy
by
running the code import sharkpy
. The sharkpy
module includes a function heavy
that takes as input an
array of shark weights and returns a smaller array containing only the
weights that are above 10 kilograms.
Using the heavy
function and an array method of
your choice, write an expression that evaluates to the weight,
in kilograms, of the lightest leopard shark in weights
that
weighs more than 10 kilograms.
Answer:
sharkpy.heavy(weights).min()
The average score on this problem was 59%.
Suppose we run the following code.
creatures = "crab, eel, clam"
oceans = "Pacific, Atlantic"
creatures = creatures.title()
oceans = oceans.upper()
creatures = creatures.replace("clam", "lobster")
What does the expression creatures + ", " + oceans
evaluate to? Write your answer exactly how the output
would appear in Python.
Answer:
"Crab, Eel, Clam, PACIFIC, ATLANTIC"
The average score on this problem was 66%.
Define narwhal
and jellyfish
as
follows.
narwhal = np.arange(6, 12, 3)
jellyfish = np.arange(12, 6, -3)
True or False: narwhal.sum()
and
jellyfish.sum()
evaluate to the same value.
True
False
Answer: False
The average score on this problem was 86%.
True or False: (narwhal+jellyfish)[0]
and
(narwhal+jellyfish)[1]
evaluate to the same value.
True
False
Answer: True
The average score on this problem was 92%.
The DataFrame finding_nemo
contains information about
characters in the movie Finding Nemo. Each row represents a
character, and the columns include:
"Name" (str)
: the unique name of the character (ex.
"Nemo"
, "Dory"
)
"Species" (str)
: the species of the character (ex.
"clownfish"
, "blue tang"
)
There is one character in finding_nemo
named
"Bruce"
. Which of the following lines of code evaluates to
Bruce’s species?
finding_nemo.get("Species").loc["Bruce"]
finding_nemo.get("Species").iloc["Bruce"]
finding_nemo.get("Species").loc["Bruce"].iloc[0]
finding_nemo.set_index("Name").get("Species").loc["Bruce"]
finding_nemo.set_index("Name").get("Species").iloc["Bruce"]
finding_nemo.set_index("Name").get("Species").loc["Bruce"].iloc[0]
Answer:
finding_nemo.set_index("Name").get("Species").loc["Bruce"]
The average score on this problem was 80%.