Skip to content

Commit

Permalink
update fa24 midterm q07 explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
hgnzheng committed Nov 20, 2024
1 parent 4ce35d2 commit 4757fe2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
58 changes: 58 additions & 0 deletions docs/fa24-midterm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,26 @@ <h1 class="title"> </h1>
</header>
<p><strong>Answer</strong>:
<code>candy_bowl, 3, replace=False</code></p>
<p>The question asks us to “take 3 candies from the bowl at random.” In
this part, we need to sample 3 candies at random using
<code>np.random.choice</code>. Now, we evaluate each option one by one
as follows:</p>
<ul>
<li><p><code>candy_bowl, len(candy_bowl), replace=False</code>: The code
tries to sample all candies without replacement. However, we are asked
to only sample three candies, not all.</p></li>
<li><p><code>candy_bowl, 3, replace=False</code>: The code samples three
candies without replacement, which matches the description. This option
is correct.</p></li>
<li><p><code>candy_bowl, 3, replace=True</code>: The code samples three
candies from the bowl with replacement. Under this setting, the same
candy can be selected multiple times in a single grab, which is not
realistic.</p></li>
<li><p><code>candy_bowl, repetitions, replace=True</code>: This option
attempts to sample <code>repetitions</code> (10,000) candies in a single
grab. We are asked to sample three candies per iteration of the loop,
not thousands.</p></li>
</ul>
<hr/>
<h5>Difficulty: ⭐️⭐️</h5>
<p>
Expand Down Expand Up @@ -733,6 +753,31 @@ <h1 class="title"> </h1>
</header>
<p><strong>Answer</strong>:
<code>grab[0] == grab[1] and grab[0] == grab[2]</code></p>
<p>Here, we need condition that checks if all three candies selected in
the grab are the same. We now analyze each option as follows:</p>
<ul>
<li><p><code>grab[0] == "Rolo" and grab[1] == "Rolo" and grab[2] == "Rolo"</code>:
This condition explicitly checks if all three candies are “Rolo”. While
it ensures that the three candies are the same, it only works for “Rolo”
and not for other types of candy in the bowl (e.g., “Twix,”
“M&amp;M”).</p></li>
<li><p><code>grab[0] == grab[1] and grab[0] == grab[2]</code>: This
condition checks if the first candy (grab[0]) is the same as the second
(grab[1]) and the third (grab[2]). If all three candies are the same
type (regardless of which type), this condition will evaluate to True.
Otherwise, the expression will evaluate to False, which is what we need.
The option is correct.</p></li>
<li><p><code>grab[0] == grab[1] or grab[0] == grab[2]</code>: This
condition checks if the first candy (grab[0]) matches either the second
(grab[1]) or the third (grab[2]). It does not require all three candies
to be the same. For example, if grab = [“Twix”, “Twix”, “M&amp;M”], this
condition would incorrectly evaluate to True.</p></li>
<li><p><code>grab == "Rolo" | grab == "M&amp;M"</code>: This condition
is syntactically invalid. It tries to compare the grab list (which
contains three elements) with two strings (“Rolo” and “M&amp;M”) using a
bitwise OR (|), not to mention that it does not check if three candies
are the same.</p></li>
</ul>
<hr/>
<h5>Difficulty: ⭐️</h5>
<p>
Expand Down Expand Up @@ -765,6 +810,19 @@ <h2 class="accordion-header" id="heading7_3">
<h1 class="title"> </h1>
</header>
<p><strong>Answer</strong>: <code>prob_all_same / repetitions</code></p>
<p>To calculate the estimated probability of drawing three candies of
the same type, we divide the total number of successes
(<code>prob_all_same</code>, which counts the instances where all three
candies are identical) by the total number of iterations
(<code>repetitions</code>).</p>
<p>The option <code>prob_all_same.mean()</code> is incorrect because
<code>prob_all_same</code> is an integer that accumulates the count of
successful trials, not an array or list that supports the
<code>.mean()</code> method. Similarly, dividing by
<code>len(candy_bowl)</code> or <code>3</code> is incorrect, as neither
represents the total number of iterations. Therefore, using these values
as the denominator would not provide an accurate probability
estimate.</p>
<hr/>
<h5>Difficulty: ⭐️⭐️</h5>
<p>
Expand Down
25 changes: 25 additions & 0 deletions problems/fa24-midterm/q07.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ What goes in blank (a)?

**Answer**: `candy_bowl, 3, replace=False`

The question asks us to "take 3 candies from the bowl at random." In this part, we need to sample 3 candies at random using `np.random.choice`. Now, we evaluate each option one by one as follows:

- `candy_bowl, len(candy_bowl), replace=False`: The code tries to sample all candies without replacement. However, we are asked to only sample three candies, not all.

- `candy_bowl, 3, replace=False`: The code samples three candies without replacement, which matches the description. This option is correct.

- `candy_bowl, 3, replace=True`: The code samples three candies from the bowl with replacement. Under this setting, the same candy can be selected multiple times in a single grab, which is not realistic.

- `candy_bowl, repetitions, replace=True`: This option attempts to sample `repetitions` (10,000) candies in a single grab. We are asked to sample three candies per iteration of the loop, not thousands.

<average>88</average>

# END SOLUTION
Expand All @@ -50,6 +60,17 @@ What goes in blank (b)?

**Answer**: `grab[0] == grab[1] and grab[0] == grab[2]`

Here, we need condition that checks if all three candies selected in the grab are the same. We now analyze each option as follows:

- `grab[0] == "Rolo" and grab[1] == "Rolo" and grab[2] == "Rolo"`: This condition explicitly checks if all three candies are "Rolo". While it ensures that the three candies are the same, it only works for "Rolo" and not for other types of candy in the bowl (e.g., "Twix," "M&M").

- `grab[0] == grab[1] and grab[0] == grab[2]`: This condition checks if the first candy (grab[0]) is the same as the second (grab[1]) and the third (grab[2]). If all three candies are the same type (regardless of which type), this condition will evaluate to True. Otherwise, the expression will evaluate to False, which is what we need. The option is correct.

- `grab[0] == grab[1] or grab[0] == grab[2]`: This condition checks if the first candy (grab[0]) matches either the second (grab[1]) or the third (grab[2]). It does not require all three candies to be the same. For example, if grab = ["Twix", "Twix", "M&M"], this condition would incorrectly evaluate to True.

- `grab == "Rolo" | grab == "M&M"`: This condition is syntactically invalid. It tries to compare the grab list (which contains three elements) with two strings ("Rolo" and "M&M") using a bitwise OR (|), not to mention that it does not check if three candies are the same.


<average>92</average>

# END SOLUTION
Expand All @@ -69,6 +90,10 @@ What goes in blank (c)?

**Answer**: `prob_all_same / repetitions`

To calculate the estimated probability of drawing three candies of the same type, we divide the total number of successes (`prob_all_same`, which counts the instances where all three candies are identical) by the total number of iterations (`repetitions`).

The option `prob_all_same.mean()` is incorrect because `prob_all_same` is an integer that accumulates the count of successful trials, not an array or list that supports the `.mean()` method. Similarly, dividing by `len(candy_bowl)` or `3` is incorrect, as neither represents the total number of iterations. Therefore, using these values as the denominator would not provide an accurate probability estimate.

<average>86</average>

# END SOLUTION
Expand Down

0 comments on commit 4757fe2

Please sign in to comment.