You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The big idea here is <ahref="reference.html#encapsulation">encapsulation</a>, and it’s the key to writing correct, comprehensible programs. A function’s job is to turn several operations into one so that we can think about a single function call instead of a dozen or a hundred statements each time we want to do something. That only works if functions don’t interfere with each other; if they do, we have to pay attention to the details once again, which quickly overloads our short-term memory.</p>
81
81
<sectionclass="challenge panel panel-success">
82
82
<divclass="panel-heading">
83
-
<h2id="following-the-call-stack"><spanclass="glyphicon glyphicon-pencil"></span>Following the call stack</h2>
83
+
<h2><spanclass="glyphicon glyphicon-pencil"></span>Following the call stack</h2>
84
84
</div>
85
85
<divclass="panel-body">
86
86
<p>We previously wrote functions called <code>fence</code> and <code>outer</code>. Draw a diagram showing how the call stack changes when we run the following:</p>
<p>The obvious thing to do with a grid like this is color in its cells, but in order to do that, we need to know how computers represent color. The most common schemes are <ahref="reference.html#rgb">RGB</a>, which is short for “red, green, blue”. RGB is an <ahref="reference.html#additive-color-model">additive color model</a>: every shade is some combination of red, green, and blue intensities. We can think of these three values as being the axes in a cube:</p>
109
108
<divclass="figure">
110
-
<imgsrc="fig/color-cube.png" alt="RGB Color Cube" />
111
-
<pclass="caption">RGB Color Cube</p>
109
+
<imgsrc="fig/color-cube.png" alt="RGB Color Cube" /><pclass="caption">RGB Color Cube</p>
112
110
</div>
113
111
<p>An RGB color is an example of a multi-part value: like a Cartesian coordinate, it is one thing with several parts. We can represent such a value in Python using a <ahref="reference.html#tuple">tuple</a>, which we write using parentheses instead of the square brackets used for a list:</p>
<p>Simple color values like <code>(0,255,0)</code> are easy enough to decipher with a bit of practice, but what color is <code>(214,90,127)</code>? To help us, <code>ipythonblocks</code> provides a function called <code>show_color</code>:</p>
<p>Will changing the nesting of the loops in the code above — i.e., wrapping the Y-axis loop around the X-axis loop — change the final image? Why or why not?</p>
193
191
</div>
194
192
</section>
195
193
<sectionclass="challenge panel panel-success">
196
194
<divclass="panel-heading">
197
-
<h2id="where-to-change-data"><spanclass="glyphicon glyphicon-pencil"></span>Where to change data</h2>
195
+
<h2><spanclass="glyphicon glyphicon-pencil"></span>Where to change data</h2>
198
196
</div>
199
197
<divclass="panel-body">
200
198
<p>Why did we transpose our data outside our heat map function? Why not have the function perform the transpose?</p>
201
199
</div>
202
200
</section>
203
201
<sectionclass="challenge panel panel-success">
204
202
<divclass="panel-heading">
205
-
<h2id="design-choice-return-versus-display"><spanclass="glyphicon glyphicon-pencil"></span>Design choice: return versus display</h2>
203
+
<h2><spanclass="glyphicon glyphicon-pencil"></span>Design choice: return versus display</h2>
206
204
</div>
207
205
<divclass="panel-body">
208
206
<p>Why does the heat map function return the grid rather than displaying it immediately? Do you think this is a good or bad design choice?</p>
0 commit comments