← 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 .
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 * lionAfter 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.
The average score on this problem was 60%.
Consider the following four assignment statements.
bass = "5"
tuna = 2
sword = ["4.0", 5, 12.5, -10, "2023"]
gold = [4, "6", "CSE", "doc"]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.
The average score on this problem was 48%.
Which of the following expressions results in an error?
int(sword[0])
float(sword[1])
int(sword[2])
int(sword[3])
float(sword[4])
Answer: int(sword[0])
“44.0” isn’t directly convertible to an int (it would be a float) so the conversion fails.
The average score on this problem was 51%.
Which of the following expressions evaluates to
"DSC10"?
gold[3].replace("o", "s").title() + str(gold[0] + gold[1])
gold[3].replace("o", "s").upper() + str(gold[0] + int(gold[1]))
gold[3].replace("o", "s").upper() + str(gold[1] + int(gold[0]))
gold[3].replace("o", "s").title() + str(gold[0] + int(gold[1]))
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.
The average score on this problem was 92%.
Consider the following assignment statement.
puffin = np.array([5, 9, 13, 17, 21])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.
The average score on this problem was 90%.
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: 2y: anything in (8,
10]z: 5Let’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.
The average score on this problem was 74%.
Suppose students is a DataFrame of all students who took
DSC 10 last quarter. students has one row per student,
where:
The index contains students’ PIDs as strings starting with
"A".
The "Overall" column contains students’ overall
percentage grades as floats.
The "Animal" column contains students’ favorite
animals as strings.
What type is students.get("Overall")? If this expression
errors, select “this errors."
float
string
array
Series
this errors
Answer: Series
.get() without brackets in the argument returns a series.
The average score on this problem was 73%.
What type is students.get("PID")? If this expression
errors, select “this errors."
float
string
array
Series
this errors
Answer: this errors
“PID” is not a column, so it errors.
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.
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
The average score on this problem was 69%.
If students wasn’t already sorted by
"Overall" in descending order, which of your answers would
need to change?
Neither y nor z would need to change
Both y and z would need to change
y only
z only
Answer: z only
The average score on this problem was 82%.