← return to practice.dsc10.com
Instructor(s): Peter Chi, Janine Tiefenbruck
This exam was administered in-person. The exam was closed-notes, except students were allowed to bring their own double-sided cheat sheet. No calculators were allowed. Students had 50 minutes to take this exam.
⚠️ PDF version available here .
Campuswire is an online discussion forum used by many college courses, including DSC 10. Students and instructional staff use it to ask questions, share announcements, and discuss course material.
The DataFrame posts has one row for every post made on a course’s Campuswire forum. The columns are:
"post_id" (int): A unique ID number for the post."title" (str): The title of the post."date" (str): The date the post was made, formatted as "YYYY-MM-DD", for example "2026-02-03"."author_role" (str): The role of the author, either "student" or "staff"."category" (str): The category the post was filed under, such as "General", "Quiz 1", "Projects", or "Homework 3"."is_private" (bool): True if the post is visible only to the author and course staff, and False if it is visible to the whole class."is_question" (bool): True if the post is a question, and False if it is a note (such as an announcement or reminder)."is_resolved" (bool): True if the post has been marked as resolved, and False otherwise."num_views" (int): The number of times the post has been viewed."num_likes" (int): The number of likes the post has received."num_comments" (int): The number of comments on the post.The first few rows of posts are shown below, though posts has many more rows than pictured.

Throughout this exam, we will refer to posts repeatedly. Assume that we have already run import babypandas as bpd and import numpy as np.
Write one line of code to create a horizontal bar chart showing both the average "num_likes" and the average "num_comments" for each "category". On a DataFrame of just the 5 rows shown in the data description, it would look like the image below.

Answer: posts.get(["category", "num_likes", "num_comments"]).groupby("category").mean().plot(kind="barh")
After a particularly difficult DSC 10 quiz, students flood Campuswire with questions. The course staff scramble to respond, but each new question has only a 40% chance of receiving a response within ten minutes, independently of other questions.
For all parts, give your answer as a mathematical expression. You do not need to simplify.
What is the probability that the first two questions do not receive responses within ten minutes, but the third question does?
Answer: 0.6^2 \cdot 0.4
What is the probability that exactly two of the first three questions receive a response within ten minutes?
Answer: 3 \cdot 0.4^2 \cdot 0.6
What is the probability that none of the first three questions receive responses within ten minutes?
Answer: 0.6^3
Given that exactly one of the first three questions receives a response within ten minutes, what is the probability that it is the third question?
Answer: \frac{1}{3}
Let a, b, c, and d represent the correct answers to parts (a), (b), (c), and (d), respectively.
Given that at least one of the first three questions receives a response within ten minutes, what is the probability that the third question is the only one to receive a response within ten minutes?
\dfrac{d}{a+b}
\dfrac{a}{1-c}
\dfrac{d}{1-c}
\dfrac{a}{a+b}
Answer: \dfrac{a}{1-c}
Define a Series containing the first five values in the "num_comments" column:
five = posts.take(np.arange(5)).get("num_comments")Determine the value of each of the following expressions.
10 + five.sum()
Answer: 25
(10 + five).sum()
Answer: 65
((five + (five >= 5).sum()) >= 5).sum()
Answer: 2
Suppose we want the function convert_to_month to take a string in the format of "YYYY-MM-DD" and return the month as an integer. Fill in the blanks in the code below.
def convert_to_month(x):
return __(a)__(x.__(b)__[1])Answer:
(a): int(b): split("-")Next, we want post_months to evaluate to a Series with the month (as an integer) that each post was made on Campuswire, in the same order as the rows appear in the DataFrame. Fill in the blanks in the code below.
post_months = posts.__(c)__.__(d)__Answer:
(c): get("date")(d): apply(convert_to_month)Which of the following evaluates to the title of the question with the third-highest number of views? Select all that apply.
posts.sort_values("num_views", ascending=False).get("title").iloc[2]
posts[posts.get("is_question") == True].get(["title", "num_views"]).set_index("title").sort_values("num_views", ascending=False).index[2]
posts[posts.get("is_question")].sort_values("num_views", ascending=False).get("title").loc[2]
posts[posts.get("is_question") == True].sort_values("num_views", ascending=False).get("title").iloc[2]
posts[posts.get("is_question")].sort_values("num_views", ascending=False).get("title").iloc[-3]
None of the above.
Answer:
posts[posts.get("is_question") == True].get(["title", "num_views"]).set_index("title").sort_values("num_views", ascending=False).index[2]posts[posts.get("is_question") == True].sort_values("num_views", ascending=False).get("title").iloc[2]Which of the following evaluates to the number of views of the post with "post_id" 104? Select all that apply.
posts.get("num_views").loc[3]
posts.get("num_views").iloc[3]
posts.set_index("post_id").get("num_views").loc[104]
posts.set_index("post_id").get("num_views").iloc[104]
posts.sort_values("num_views").get("num_views").iloc[3]
posts.sort_values("num_views").get("num_views").loc[3]
posts[posts.get("post_id") == 104].get("num_views").iloc[0]
None of the above.
Answer:
posts.get("num_views").loc[3]posts.get("num_views").iloc[3]posts.set_index("post_id").get("num_views").loc[104]posts.sort_values("num_views").get("num_views").loc[3]posts[posts.get("post_id") == 104].get("num_views").iloc[0]Suppose we divide student-authored posts into four categories as follows:
Fill in the blanks in the code below to create a DataFrame called max_likes with four rows and a single column containing the largest number of likes on a single post in each of these four categories. The rows can be in any order (not necessarily matching the order given above).
student_posts = posts[__(a)__]
max_likes = student_posts.get(__(b)__).groupby(__(c)__).__(d)__Answer:
(a): posts.get("author_role") == "student"(b): ["is_private", "is_resolved", "num_likes"](c): ["is_private", "is_resolved"](d): max()First, filter posts to include only student-authored posts by checking whether "author_role" equals "student".
Next, select the columns "is_private", "is_resolved", and "num_likes", then group by "is_private" and "is_resolved". Finally, apply max() to find the largest number of likes in each category. Since both grouping columns are Boolean, the result has up to four rows, one for each combination of privacy and resolution status.
Vanessa authored five of the posts included in posts. We define a DataFrame called vanessa containing only Vanessa’s posts, and keeping only certain columns. This DataFrame is shown in full below.

What does the following expression evaluate to?
vanessa.merge(vanessa, left_on="num_likes", right_on="num_comments").shape[0]Answer: 8
Two left rows with 0 likes each match three right rows with 0 comments, giving 6 matches. The rows with 2 and 3 likes contribute one match each.
Suppose the array assignments contains the names of all assignments in a course. For example, assignments[0] might be "Homework 1".
Suppose also that the array due_dates contains the deadlines for all assignments in the course, in the same order as in assignments. In particular, both arrays have the same length. The entries of due_dates are strings formatted like "YYYY-MM-DD". For example, due_dates[0] might be "2026-01-12".
Our goal in this problem is to create a string called reminders that contains sentences describing when each assignment is due, with one space after each sentence. For example, in a class with only three assignments, the output may look like this:
"Homework 1 is due on 2026-01-12. Homework 2 is due on 2026-01-17. Midterm Project is due on 2026-01-25. "
Complete the for-loop below so that reminders is a string formatted like the above example, using all the assignments and deadlines in assignments and due_dates.
reminders = __(a)__
for i in __(b)__:
reminders = __(c)__Answer:
(a): ""(b): np.arange(len(assignments)) or np.arange(len(due_dates))(c): reminders + assignments[i] + " is due on " + due_dates[i] + ". "The course tutors are constantly competing to give the best, most thoughtful answers on Campuswire. To determine who is the nicest tutor, the course staff run a weekly Kindness Check: they select 4 posts at random, without replacement, from posts and read every tutor reply on them. Since only questions receive replies, Jeffrey is hoping that the Kindness Check lands on more questions than notes. That way, he has more chances to show everyone just how nice he can be.
Fill in the blanks below so that prob_more_questions is an estimate of the probability that a Kindness Check contains more questions than notes.
repetitions = 10000
count = 0
for i in np.arange(repetitions):
check = np.random.choice(__(a)__)
if __(b)__:
count = count + 1
prob_more_questions = count / repetitionsWhich of the following correctly fills in blank (a)? Select one.
posts, 4, replace=True
posts, 4, replace=False
posts.get("is_question"), 4, replace=True
posts.get("is_question"), 4, replace=False
np.array([True, False]), 4, replace=True
np.array([True, False]), 4, replace=False
Answer: posts.get("is_question"), 4, replace=False
Which of the following could go in blank (b)? Select all that apply.
np.count_nonzero(check) >= 3
np.count_nonzero(check) >= 2
np.count_nonzero(check) > 0.5
check.sum() > (4 - (check).sum())
check.mean() > 0.5
None of the above.
Answer:
np.count_nonzero(check) >= 3check.sum() > (4 - (check).sum())check.mean() > 0.5Jeffrey copies the correct simulation into his own notebook, but in his excitement, he accidentally moves the line count = 0 to the inside of the for-loop:
repetitions = 10000
for i in np.arange(repetitions):
count = 0
check = np.random.choice(__(a)__)
if __(b)__:
count = count + 1
prob_more_questions = count / repetitionsAssuming that blanks (a) and (b) are filled in correctly, which of the following could prob_more_questions evaluate to after Jeffrey’s code finishes running? Select all that apply.
0.0
0.0001
0.5
1.0
None of the above.
Answer:
0.00.0001The density histograms below show response times for 300 public and 100 private student questions. All values are exact.

How many private questions took at least 40 minutes to receive a response? Give your answer as an integer.
Answer: 50
The fraction below 40 minutes is 20(0.015) + 20(0.01) = 0.5, so 100(1 - 0.5) = 50.
Suppose we make a single density histogram for all 400 questions, with one bin being [0, 10). What would the height of this bar be?
\dfrac{3}{200} = 0.015
\dfrac{7}{400} = 0.0175
\dfrac{1}{50} = 0.02
\dfrac{11}{400} = 0.0275
\dfrac{7}{200} = 0.035
Not enough information.
Answer: Not enough information.
Suppose we make a single density histogram for all 400 questions, with one bin being [20, 40). What would the height of this bar be?
\dfrac{1}{80} = 0.0125
\dfrac{11}{800} = 0.01375
\dfrac{3}{200} = 0.015
\dfrac{1}{40} = 0.025
\dfrac{11}{40} = 0.275
Not enough information.
Answer: \dfrac{11}{800} = 0.01375