Skip to content

Commit

Permalink
hide solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
jlobue committed Oct 3, 2023
1 parent 9157290 commit 11d5fbb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 161 deletions.
161 changes: 2 additions & 159 deletions docs/disc01/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ <h1 class="title">Discussion 1: Intro + Python Basics</h1>
<hr />
<p>Welcome! The problems shown below should be worked on <strong>on
paper</strong>, since the quizzes and exams you take in this course will
also be on paper. <br>We encourage you to complete this worksheet in a
live discussion section. Solutions will be made available after all
also be on paper. <br><br>We encourage you to complete this worksheet in
a live discussion section. Solutions will be made available after all
discussion sections have concluded. You don’t need to submit your
answers anywhere.</p>
<hr />
Expand All @@ -79,28 +79,6 @@ <h3 id="problem-1.1">Problem 1.1</h3>
<li><p><input type="radio" disabled="" /> <code>str</code></p></li>
<li><p><input type="radio" disabled="" /> The price of the first product.</p></li>
</ul>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading1_1">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse1_1" aria-expanded="true" aria-controls="collapse1_1">
Click to view the solution.
</button>
</h2>
<div id="collapse1_1" class="accordion-collapse collapse collapse"
aria-labelledby="heading1_1" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer:</strong> <code>float</code></p>
<p><code>prices[0]</code> represents the price in dollars of some
product at the grocery store. The data type should be a
<code>float</code> because prices are numbers but not necessarily
integers.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<h3 id="problem-1.2">Problem 1.2</h3>
<p>What does <code>type(calories[0])</code> evaluate to?</p>
Expand All @@ -110,85 +88,16 @@ <h3 id="problem-1.2">Problem 1.2</h3>
<li><p><input type="radio" disabled="" /> <code>str</code></p></li>
<li><p><input type="radio" disabled="" /> The calories in the first product.</p></li>
</ul>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading1_2">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse1_2" aria-expanded="true" aria-controls="collapse1_2">
Click to view the solution.
</button>
</h2>
<div id="collapse1_2" class="accordion-collapse collapse collapse"
aria-labelledby="heading1_2" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer:</strong> <code>int</code></p>
<p>Similarly, <code>calories[0]</code> represents the calories in some
product at the grocery store. The data type should be <code>int</code>
because calories in foods are always reported as integers.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<h3 id="problem-1.3">Problem 1.3</h3>
<p>When we divide two arrays of the same length, their corresponding
elements get divided, and the result is a new array of the same length
as the two originals. In one sentence, interpret the meaning of
<code>min(prices / calories)</code>.</p>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading1_3">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse1_3" aria-expanded="true" aria-controls="collapse1_3">
Click to view the solution.
</button>
</h2>
<div id="collapse1_3" class="accordion-collapse collapse collapse"
aria-labelledby="heading1_3" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer:</strong> This is the cost per calorie of the product
which has the lowest cost per calorie, which you might say is the
cheapest food to fuel up on (like instant ramen or pasta).</p>
</div>
</div>
</div>
</div>
<p><br></p>
<h3 id="problem-1.4">Problem 1.4</h3>
<p>True or false: <code>min(prices / calories)</code> is the same as
<code>max(calories / price)</code>.</p>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading1_4">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse1_4" aria-expanded="true" aria-controls="collapse1_4">
Click to view the solution.
</button>
</h2>
<div id="collapse1_4" class="accordion-collapse collapse collapse"
aria-labelledby="heading1_4" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer:</strong> False</p>
<p>The former is measured in dollars per calories (a very small number),
whereas the latter is measured in calories per dollar (a very big
number).</p>
<p>However, there is a connection between these two values. The product
that has the lowest price per calorie is the same product with the most
calories per dollar. So these numbers refer to the same grocery store
product, and we can convert one value into the other by taking the
reciprocal, which swaps the numerator and denominator of a fraction.
Therefore, it’s true that <code>min(prices / calories)</code> is the
same as <code>1 / max(calories / price)</code>.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<hr />
<h2 id="problem-2">Problem 2</h2>
Expand All @@ -201,75 +110,9 @@ <h2 id="problem-2">Problem 2</h2>
<h3 id="problem-2.1">Problem 2.1</h3>
<p>How many function calls are there in this expression? How many
arguments does each function have?</p>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading2_1">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse2_1" aria-expanded="true" aria-controls="collapse2_1">
Click to view the solution.
</button>
</h2>
<div id="collapse2_1" class="accordion-collapse collapse collapse"
aria-labelledby="heading2_1" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer:</strong> 4 function calls: one argument for
<code>int()</code>, one for <code>math.sqrt()</code>, two for
<code>math.pow()</code>, three for <code>min()</code>.</p>
<p>There are four function calls. One is a call to the type-conversion
function <code>int()</code>, which takes one argument. Another is a call
to <code>math.sqrt()</code>, which takes one argument. Another is a call
to <code>math.pow()</code>, which takes two arguments. Finally is a call
to the built-in function <code>min()</code>, which in this case takes
three arguments, but generally can take two or more arguments.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<h3 id="problem-2.2">Problem 2.2</h3>
<p>What does this expression evaluate to?</p>
<div id="accordionExample" class="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="heading2_2">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse2_2" aria-expanded="true" aria-controls="collapse2_2">
Click to view the solution.
</button>
</h2>
<div id="collapse2_2" class="accordion-collapse collapse collapse"
aria-labelledby="heading2_2" data-bs-parent="#accordionExample">
<div class="accordion-body">
<header id="title-block-header">
<h1 class="title"> </h1>
</header>
<p><strong>Answer:</strong> 8</p>
<p>For nested evaluation, it is helpful to work from the inside out.
Let’s evaluate some arithmetic expressions first. <code>9 % 4</code>
evaluates to <code>1</code> because when we divide <code>9</code> by
<code>4</code>, there is a remainder of <code>1</code>. Additionally,
<code>9 / 4</code> evaluate to <code>2.25</code>, and <code>9 - 4</code>
evaluates to <code>5</code>. Starting with the inner most function call,
we see <code>min(9 % 4, 9 / 4, 9 - 4)</code> is equiavlent to
<code>min(1, 2.25, 5)</code> which evaluates to <code>1</code>.</p>
<p>The next-most inner function call is the call to
<code>math.pow()</code> which takes two arguments: a number for the
base, and a number for the exponent. We’ve already evaluated the
exponent, but we need to evaluate the base of <code>4 * 2 ** 4</code>.
Using the order of operations, we know we need to evaluate the exponent
first. So <code>4 * 2 ** 4</code> is equivalent to <code>4 * 16</code>
or <code>64</code>.</p>
<p>Therefore,
<code>math.pow(4 * 2 ** 4, min(9 % 4, 9 / 4, 9 - 4))</code> simplifies
to <code>math.pow(64, 1)</code>, which Python evaluates to be
<code>64.0</code>, a <code>float</code>.</p>
<p>Next, <code>math.sqrt(64.0)</code> evaluates to <code>8.0</code>.
Finally, the type conversion function <code>int(8.0)</code> evaluates to
<code>8</code>.</p>
</div>
</div>
</div>
</div>
<p><br></p>
<hr />
<h2 id="section"><span class="math display"> </span></h2>
Expand Down
4 changes: 2 additions & 2 deletions pages/disc/disc01.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
title: 'Discussion 1: Intro + Python Basics'
context: >
Welcome! The problems shown below should be worked on **on paper**, since the quizzes and exams you take in this course will also be on paper.
<br>We encourage you to complete this worksheet in a live discussion section.
<br><br>We encourage you to complete this worksheet in a live discussion section.
Solutions will be made available after all discussion sections have concluded. You don't need to submit your answers anywhere.
show_solution: true
show_solution: false
problems:
- disc/disc01-datatypes_math
- disc/disc01-expressions_math

0 comments on commit 11d5fbb

Please sign in to comment.