Skip to content

Commit b76791e

Browse files
committed
publish dart problem
1 parent 4120558 commit b76791e

File tree

181 files changed

+9165
-3902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+9165
-3902
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

docs/.doctrees/environment.pickle

6.11 KB
Binary file not shown.
60 Bytes
Binary file not shown.

docs/.doctrees/module_5.doctree

8 Bytes
Binary file not shown.

docs/Module2_EssentialsOfPython/ConditionalStatements.html

+3
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ <h2><code class="docutils literal notranslate"><span class="pre">if</span></code
431431
<span class="n">status</span> <span class="o">=</span> <span class="s2">&quot;dead&quot;</span>
432432
</pre></div>
433433
</div>
434+
<p>Each <code class="docutils literal notranslate"><span class="pre">if</span></code>, <code class="docutils literal notranslate"><span class="pre">elif</span></code>, and <code class="docutils literal notranslate"><span class="pre">else</span></code> statement must end in a colon
435+
character, and the body of each of these statements is <a class="reference external" href="https://www.pythonlikeyoumeanit.com/Module2_EssentialsOfPython/Introduction.html#Python-Uses-Whitespace-to-Delimit-Scope">delimited by
436+
whitespace</a>.</p>
434437
<p>The following pseudo-code demonstrates the general template for
435438
conditional statements:</p>
436439
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="o">&lt;</span><span class="n">expression_1</span><span class="o">&gt;</span><span class="p">:</span>

docs/Module2_EssentialsOfPython/ForLoops.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ <h2>For-Loops<a class="headerlink" href="#For-Loops" title="Permalink to this he
260260
<p>Where <code class="docutils literal notranslate"><span class="pre">&lt;var&gt;</span></code> is any valid variable-identifier and <code class="docutils literal notranslate"><span class="pre">&lt;iterable&gt;</span></code> is
261261
any <strong>iterable</strong>. We will discuss iterables more formally in the next
262262
section; suffice it to know that every sequence-type object is an
263-
iterable. The “body” of the for-loop is the code indented beneath the
264-
for-loop statement.</p>
263+
iterable. The <code class="docutils literal notranslate"><span class="pre">for</span></code>statement must end in a colon character, and the
264+
body the for-loop is
265+
<a class="reference external" href="https://www.pythonlikeyoumeanit.com/Module2_EssentialsOfPython/Introduction.html#Python-Uses-Whitespace-to-Delimit-Scope">whitespace-delimited</a>.</p>
265266
<p>The for-loop behaves as follows:</p>
266267
<ul class="simple">
267268
<li>Request the next member of the iterable.</li>

docs/Module2_EssentialsOfPython/Functions.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ <h2>The <code class="docutils literal notranslate"><span class="pre">def</span><
303303
<li><code class="docutils literal notranslate"><span class="pre">&lt;function</span> <span class="pre">name&gt;</span></code> can be any valid variable name, and <em>must</em> be
304304
followed by parentheses and then a colon.</li>
305305
<li><code class="docutils literal notranslate"><span class="pre">&lt;function</span> <span class="pre">signature&gt;</span></code> specifies the input arguments to the
306-
function, and may be left blank (if the function does not accept any
307-
arguments).</li>
306+
function, and may be left blank if the function does not accept any
307+
arguments (the parentheses must still be included, but will not
308+
encapsulate anything).</li>
308309
<li>The documentation string (commonly referred to as a “docstring”) may
309310
span multiple lines, and should indicate what the function’s purpose
310311
is. It is optional.</li>
@@ -316,8 +317,9 @@ <h2>The <code class="docutils literal notranslate"><span class="pre">def</span><
316317
<p>The <code class="docutils literal notranslate"><span class="pre">return</span></code> statement is also reserved by Python. It denotes the end
317318
of a function; if reached, a <code class="docutils literal notranslate"><span class="pre">return</span></code> statement immediately concludes
318319
the execution of the function and returns the specified object.</p>
319-
<p>Note that, like an if-statement and a for-loop, the content of a
320-
function is indicated by indentation:</p>
320+
<p>Note that, like an if-statement and a for-loop, the <code class="docutils literal notranslate"><span class="pre">def</span></code> statment
321+
must end in a colon and the body of the function is <a class="reference external" href="https://www.pythonlikeyoumeanit.com/Module2_EssentialsOfPython/Introduction.html#Python-Uses-Whitespace-to-Delimit-Scope">delimited by
322+
whitespace</a>:</p>
321323
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># wrong indentation</span>
322324
<span class="k">def</span> <span class="nf">bad_func1</span><span class="p">():</span>
323325
<span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>

docs/Module2_EssentialsOfPython/Generators_and_Comprehensions.html

+15-6
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ <h2>Creating your own generator: generator comprehensions<a class="headerlink" h
381381

382382
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">example_gen</span><span class="p">:</span>
383383
<span class="k">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
384-
<span class="c1"># prints: 0.5.. 4.5.. 10.5.. 16.0</span>
384+
<span class="c1"># prints: 0.0.. 4.5.. 10.5.. 16.0</span>
385385
</pre></div>
386386
</div>
387387
<p><code class="docutils literal notranslate"><span class="pre">&lt;expression&gt;</span></code> can be any valid single-line of Python code that
@@ -421,10 +421,9 @@ <h2>Creating your own generator: generator comprehensions<a class="headerlink" h
421421
<div class="admonition warning">
422422
<p class="first fa fa-exclamation-circle"><strong>Note</strong>:</p>
423423
<p class="last">Generator comprehensions are <strong>not</strong> the only method for defining
424-
generators in Python. We will briefly introduced a more fully-fledged
425-
syntax for defining generators. One can define a generator similar to
426-
the way one can define a function (which we will encounter soon). <a class="reference external" href="https://docs.python.org/3/tutorial/classes.html#generators">See
427-
this section of the official Python
424+
generators in Python. One can define a generator similar to the way one
425+
can define a function (which we will encounter soon). <a class="reference external" href="https://docs.python.org/3/tutorial/classes.html#generators">See this section
426+
of the official Python
428427
tutorial</a>
429428
if you are interested in diving deeper into generators.</p>
430429
</div>
@@ -531,10 +530,20 @@ <h3>Chaining comprehensions<a class="headerlink" href="#Chaining-comprehensions"
531530
<span class="o">&gt;&gt;&gt;</span> <span class="n">gen_1</span> <span class="o">=</span> <span class="p">(</span><span class="n">i</span><span class="o">**</span><span class="mi">2</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="o">-</span><span class="mi">20</span><span class="p">,</span> <span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">])</span>
532531

533532
<span class="c1"># sums the generated numbers, excluding any numbers whose absolute value is greater than 150</span>
534-
<span class="o">&gt;&gt;&gt;</span> <span class="nb">sum</span><span class="p">(</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">gen_1</span> <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">150</span><span class="p">)</span>
533+
<span class="o">&gt;&gt;&gt;</span> <span class="nb">sum</span><span class="p">(</span><span class="n">j</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">gen_1</span> <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">j</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">150</span><span class="p">)</span>
535534
<span class="mi">200</span>
536535
</pre></div>
537536
</div>
537+
<p>This is equivalent to:</p>
538+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">total</span> <span class="o">=</span> <span class="mi">0</span>
539+
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="o">-</span><span class="mi">20</span><span class="p">,</span> <span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">]:</span>
540+
<span class="n">j</span> <span class="o">=</span> <span class="n">i</span> <span class="o">**</span> <span class="mi">2</span>
541+
<span class="k">if</span> <span class="n">j</span> <span class="o">&lt;=</span> <span class="mi">150</span><span class="p">:</span>
542+
<span class="n">total</span> <span class="o">+=</span> <span class="n">j</span>
543+
544+
<span class="c1"># total is now 200</span>
545+
</pre></div>
546+
</div>
538547
</div>
539548
<div class="section" id="Using-generator-comprehensions-on-the-fly">
540549
<h3>Using generator comprehensions on the fly<a class="headerlink" href="#Using-generator-comprehensions-on-the-fly" title="Permalink to this headline"></a></h3>

docs/Module2_EssentialsOfPython/Introduction.html

+101-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@
101101
<li class="toctree-l2"><a class="reference internal" href="Basic_Objects.html">Basic Object Types</a></li>
102102
<li class="toctree-l2"><a class="reference internal" href="SequenceTypes.html">Sequence Types</a></li>
103103
<li class="toctree-l2"><a class="reference internal" href="Variables_and_Assignment.html">Variables &amp; Assignment</a></li>
104-
<li class="toctree-l2 current"><a class="current reference internal" href="#">Introducing Control Flow</a></li>
104+
<li class="toctree-l2 current"><a class="current reference internal" href="#">Introducing Control Flow</a><ul>
105+
<li class="toctree-l3"><a class="reference internal" href="#Python-Uses-Whitespace-to-Delimit-Scope">Python Uses Whitespace to Delimit Scope</a></li>
106+
</ul>
107+
</li>
105108
<li class="toctree-l2"><a class="reference internal" href="ConditionalStatements.html">Conditional Statements</a></li>
106109
<li class="toctree-l2"><a class="reference internal" href="ForLoops.html">For-Loops and While-Loops</a></li>
107110
<li class="toctree-l2"><a class="reference internal" href="Iterables.html">Iterables</a></li>
@@ -248,10 +251,11 @@ <h1>Introducing Control Flow<a class="headerlink" href="#Introducing-Control-Flo
248251
<span class="sd">&quot;&quot;&quot; Counts how many numbers in the interval [m, n] are divisible by 3. &quot;&quot;&quot;</span>
249252
<span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
250253
<span class="k">for</span> <span class="n">num</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
251-
<span class="k">if</span> <span class="n">num</span> <span class="o">%</span> <span class="mi">3</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="c1"># x % y gives the remainder of x / y</span>
254+
<span class="k">if</span> <span class="n">num</span> <span class="o">%</span> <span class="mi">3</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="c1"># recall: x % y gives the remainder of x / y</span>
252255
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
253256
<span class="k">else</span><span class="p">:</span>
254-
<span class="k">pass</span>
257+
<span class="k">pass</span> <span class="c1"># this `else-pass` statement is not really necessary</span>
258+
<span class="c1"># it is included for the sake of clarity in this introduction</span>
255259
<span class="k">return</span> <span class="n">count</span>
256260
</pre></div>
257261
</div>
@@ -271,6 +275,100 @@ <h1>Introducing Control Flow<a class="headerlink" href="#Introducing-Control-Flo
271275
<p>In the following sections, you will be formally introduced to
272276
if-elif-else blocks, for-loops &amp; iterables, and functions, all so that
273277
you can implement effective “control flow” in your code.</p>
278+
<p>Before embarking on these sections, we must take a moment to study
279+
Python’s syntax for delimiting scope for these various control flow
280+
constructs.</p>
281+
<div class="section" id="Python-Uses-Whitespace-to-Delimit-Scope">
282+
<h2>Python Uses Whitespace to Delimit Scope<a class="headerlink" href="#Python-Uses-Whitespace-to-Delimit-Scope" title="Permalink to this headline"></a></h2>
283+
<p>While the concepts of function definitions, loops, and conditional
284+
statements are shared across the majority of modern programming
285+
languages, the languages often differ in their syntax for delimiting the
286+
<em>bodies</em> of these constructs. For example, where C++ uses “curly braces”
287+
as delimiters, e.g.:</p>
288+
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="c1">// example showing that C++ uses curly braces to delimit scope</span>
289+
<span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
290+
291+
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">&gt;</span> <span class="mi">10</span><span class="p">)</span>
292+
<span class="p">{</span>
293+
<span class="c1">// we are inside the if-block, as delimited by the curly-brackets</span>
294+
<span class="n">x</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
295+
<span class="p">}</span>
296+
<span class="c1">// we are outside of the if-block</span>
297+
<span class="n">x</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">3</span><span class="p">;</span>
298+
</pre></div>
299+
</div>
300+
<p>Python <strong>uses whitespace (i.e.&nbsp;indentation) to delimit scope</strong>:</p>
301+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># example showing that Python uses whitespace to delimit scope</span>
302+
<span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
303+
304+
<span class="k">if</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">10</span><span class="p">:</span>
305+
<span class="c1"># we are inside the if-block; this line starts with four blank spaces</span>
306+
<span class="n">x</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span>
307+
<span class="c1"># we are outside of the if-block; there are no leading whitespace characters</span>
308+
<span class="n">x</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">3</span>
309+
</pre></div>
310+
</div>
311+
<p>Look to the example at the beginning of this section to see the bodies
312+
of the function definition, the for-loop, and the subsequent if-else
313+
block were all separated by increasing levels of indentation.</p>
314+
<p>Python’s syntax is quite flexible in terms of what it defines as a
315+
whitespace delimiter. Its rules are that:</p>
316+
<ul class="simple">
317+
<li>One or more whitespace characters (spaces or tabs) is sufficient to
318+
serve as indentation.</li>
319+
<li>A given indented block must use a uniform level of indentation. E.g.
320+
if the first line of an indented block has two leading spaces, all
321+
subsequent lines in that block must lead with exactly two white
322+
spaces.</li>
323+
</ul>
324+
<p>While Python’s syntax is relatively forgiving, I am not: the <a class="reference external" href="https://www.python.org/dev/peps/pep-0008/#indentation">standard
325+
style</a> for
326+
indenting in Python is to <strong>use four space characters</strong> for each level
327+
of indentation. It is strongly advised that you adhere to this standard.
328+
Most IDEs and consoles (including Jupyter notebooks) will automatically
329+
add a four-space indentation for you when you enter into the body of one
330+
of the aforementioned constructs.</p>
331+
<p>Let’s review these ruled by considering a few simple examples (including
332+
incorrect examples) of delimiting scope in Python.</p>
333+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># OK, but gross: The use of a single whitespace</span>
334+
<span class="c1"># makes the indentation hard to see. Use four spaces.</span>
335+
<span class="k">if</span> <span class="bp">True</span><span class="p">:</span>
336+
<span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1"># one space</span>
337+
<span class="n">y</span> <span class="o">=</span> <span class="mi">2</span> <span class="c1"># one space</span>
338+
</pre></div>
339+
</div>
340+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># BAD: the inconsistent level of indentation in this</span>
341+
<span class="c1"># single block will cause this code to raise an IndentationError</span>
342+
<span class="k">def</span> <span class="nf">my_func</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
343+
<span class="n">x</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span> <span class="c1"># four spaces</span>
344+
<span class="n">y</span> <span class="o">=</span> <span class="mi">3</span> <span class="c1"># eight spaces</span>
345+
<span class="n">z</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span> <span class="c1"># four spaces</span>
346+
<span class="k">return</span> <span class="n">z</span> <span class="c1"># four spaces</span>
347+
</pre></div>
348+
</div>
349+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># OK, but gross: The if-block uses four spaces as a delimiter.</span>
350+
<span class="c1"># The else-block uses two spaces as a delimiter. This is technically</span>
351+
<span class="c1"># okay since indentation is consistent within each block. One should</span>
352+
<span class="c1"># always use four spaces for indentation.</span>
353+
<span class="k">if</span> <span class="bp">True</span><span class="p">:</span>
354+
<span class="n">x</span> <span class="o">=</span> <span class="mi">3</span> <span class="c1"># four spaces</span>
355+
<span class="n">y</span> <span class="o">=</span> <span class="mi">2</span> <span class="c1"># four spaces</span>
356+
<span class="k">else</span><span class="p">:</span>
357+
<span class="n">x</span> <span class="o">=</span> <span class="mi">2</span> <span class="c1"># two spaces</span>
358+
<span class="n">y</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1"># two spaces</span>
359+
</pre></div>
360+
</div>
361+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Good! The for-loop&#39;s body is defined by one level</span>
362+
<span class="c1"># of four-space indentation, and the contained if-else</span>
363+
<span class="c1"># blocks each have their own additional four-space indentations.</span>
364+
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]:</span>
365+
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span> <span class="c1"># four spaces</span>
366+
<span class="n">x</span> <span class="o">=</span> <span class="s2">&quot;even&quot;</span> <span class="c1"># eight spaces</span>
367+
<span class="k">else</span><span class="p">:</span> <span class="c1"># four spaces</span>
368+
<span class="n">x</span> <span class="o">=</span> <span class="s2">&quot;odd&quot;</span> <span class="c1"># eight spaces</span>
369+
</pre></div>
370+
</div>
371+
</div>
274372
</div>
275373

276374

0 commit comments

Comments
 (0)