GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-107017: Rework the Fibonacci example by TommyUnreal · Pull Request #107132 · python/cpython Conversation
|
|
|
||
| A *multiple assignment* of variables us allows to set values of more than one | ||
| variable on a single line. Notice that if the value assignment is a | ||
| expression, it is first evaluated and then assigned.:: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
.:: will produce a full-stop and a colon:
.:
One or the other. I suggest losing the full-stop.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ------------------ | ||
|
|
||
| The :keyword:`while` loop is example of a repeating cycle. It performs | ||
| a block of code over as long as the condition (in example: ``a < 10``) is |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
"in example" > "for example"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What I wanted to say is that "in the example below the condition is the following expression a < 10", but that is no longer present in the examples. I will rework that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| >>> count # when count reached value of 5, while loop finished | ||
| 5 | ||
|
|
||
| Note that block inside the while loop, or *body* of the loop is *indented*. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I suggest using while, to draw attention to it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| the Python shell, you need to type a tab or space(s) for each indented line. | ||
| Each line within a block must be indented by the same amount. | ||
| When we want to exit the indented block of code in the Python shell, we must | ||
| follow it by a blank line to indicate its completion. This way, parser knows |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
"... the parser"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Each line within a block must be indented by the same amount. | ||
| When we want to exit the indented block of code in the Python shell, we must | ||
| follow it by a blank line to indicate its completion. This way, parser knows | ||
| we have finished typing the last line).:: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Again, here we have a full-stop and a colon in the output.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ... print(count, end=' ') # end the output of print() with a whitespace | ||
| ... count = count - 1 # lower the value by one with each repetition | ||
| ... | ||
| 10 9 8 7 6 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is an elegant touch.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ... print('', a, '', end='->') | ||
| ... a, b = b, a+b | ||
| ... | ||
| 0 -> 1 -> 1 -> 2 -> 3 -> 5 -> 8 -> 13 -> 21 -> 34 -> 55 -> 89 -> 144 -> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
And I like the way that the example illustrates the value of using end - no need to explain, the example does it much more effectively. This will stick in someone's mind.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Fix parts where a paragraph ended both with full-stop and colon. Added new paragraph, where example of simple loop is explained in detail. Plus warning about indefinite loops.
|
|
||
| >>> a, b = 0, 1 | ||
| >>> while a < 150: | ||
| ... print('', a, '', end='->') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I understand that this utilities the print sep param, however this is nor explained nor inferred, so to a beginner it may be confusing
Perhaps it could be beneficial to show off f-strings like
| ... print('', a, '', end='->') | |
| ... print(f'{a} ->', end='') |
Or to keep end as ->
| ... print('', a, '', end='->') | |
| ... print(f'{a} ', end="->") |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I very strongly prefer the original print('', a, '', end='->'), which reduces the punctuation the learner has to deal with to a minimum, and emphasises instead the connection between more easily assimilated things, like the English word "end" and the "arrow" ("->").
Showing off f-strings while demonstrating a different functionality introduces unnecessary cognitive burden. Two different kinds of quotes and two different kinds of brackets requires a lot of parsing and stopping. I don't think this is the right solution here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
My reasoning: As this is an Introduction chapter, I wanted to keep the number of introduced concepts to the minimum. There are ways to code this better, but it is not formally wrong. The default separator is already shown in the example above and this just builds on that, so it's hopefully not confusing to the reader.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| >>> count = 10 | ||
| >>> while count > 5: | ||
| ... print(count, end=' ') # end the output of print() with a whitespace | ||
| ... count = count - 1 # lower the value by one with each repetition |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| ... count = count - 1 # lower the value by one with each repetition | |
| ... count = count - 1 # decrement the value each iteration |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would strongly prefer "decrease the value by one".
The reason is that many people will not be familiar with the word "decrement", it's used very little in English outside technical contexts.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| >>> a, b = 1, 5 # multiple assignment of two variables | ||
| >>> a | ||
| 0 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is this a doctest bug?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Caeden Perelli-Harris <[email protected]>
Co-authored-by: Caeden Perelli-Harris <[email protected]>
More precise and clearer wording. Co-authored-by: Caeden Perelli-Harris <[email protected]>
There was an error while loading. Please reload this page.
| >>> count = 10 | ||
| >>> while count > 5: | ||
| ... print(count, end=' ') # end the output of print() with a whitespace | ||
| ... count = count - 1 # lower the value by one with each repetition |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would strongly prefer "decrease the value by one".
The reason is that many people will not be familiar with the word "decrement", it's used very little in English outside technical contexts.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| >>> a, b = 0, 1 | ||
| >>> while a < 150: | ||
| ... print('', a, '', end='->') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I very strongly prefer the original print('', a, '', end='->'), which reduces the punctuation the learner has to deal with to a minimum, and emphasises instead the connection between more easily assimilated things, like the English word "end" and the "arrow" ("->").
Showing off f-strings while demonstrating a different functionality introduces unnecessary cognitive burden. Two different kinds of quotes and two different kinds of brackets requires a lot of parsing and stopping. I don't think this is the right solution here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Other than these grammatical mistakes, looks like a good change to me
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Caeden Perelli-Harris <[email protected]>
lower the value -> decrease the value
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Very nice touch! Here are 2 cosmetic details
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987, | ||
| 4 | ||
|
|
||
| Function argumets |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Typo here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Function argumets | ||
| ----------------- | ||
|
|
||
| We already know :func:`print` function, that writes the value of the |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We already know the print function ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A suggestion and some little wording things, otherwise looks good!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| We can use Python for more complex tasks than adding two and two together. | ||
| For instance, we can compute the numbers of the | ||
| `Fibonacci series <https://en.wikipedia.org/wiki/Fibonacci_number>`_. | ||
| To do that we need to utilize three following concepts. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| To do that we need to utilize three following concepts. | |
| To do that we need to use the three following concepts. |
Let's use the plain English "use" instead of "utilize".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Multiple Assignment | ||
| ------------------- | ||
|
|
||
| A *multiple assignment* of variables us allows to set values of more than one |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| A *multiple assignment* of variables us allows to set values of more than one | |
| A *multiple assignment* of variables us allows to set the values of more than one |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ------------------- | ||
|
|
||
| A *multiple assignment* of variables us allows to set values of more than one | ||
| variable on a single line. Notice that if the value assignment is a |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| variable on a single line. Notice that if the value assignment is a | |
| variable on a single line. Notice that if the value assignment is an |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Repeating our code | ||
| ------------------ | ||
|
|
||
| The :keyword:`while` loop is example of a repeating cycle. It performs |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| The :keyword:`while` loop is example of a repeating cycle. It performs | |
| The :keyword:`while` loop is an example of a repeating cycle. It performs |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| in this case, ``count < 5``. To ensure that the loop finishes, we must make | ||
| sure that the condition is *not fulfilled* at a certain step. Otherwise, the | ||
| code would repeat indefinitely. To achieve that, we can increase the value | ||
| of count. As soon as the variable ``count`` reaches the value 5, the |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| of count. As soon as the variable ``count`` reaches the value 5, the | |
| of ``count``. As soon as the variable ``count`` reaches the value 5, the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| of count. As soon as the variable ``count`` reaches the value 5, the | ||
| condition will be ``False``:: | ||
|
|
||
| >>> count = 0; # define variable to which we will be adding 1 in a loop |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| >>> count = 0; # define variable to which we will be adding 1 in a loop | |
| >>> count = 0 # define variable to which we will be adding 1 in a loop |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| >>> while count < 5: count = count + 1 # hit enter one more time to start the loop | ||
| ... | ||
| >>> count # when count reached value of 5, while loop finished | ||
| 5 | ||
|
|
||
| Note that block inside the ``while`` loop, or *body* of the loop is *indented*. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The example above uses a one-liner: while count < 5: count = count + 1
Let's use indentation in the example, to match the text. Something like this?
| >>> while count < 5: count = count + 1 # hit enter one more time to start the loop | |
| ... | |
| >>> count # when count reached value of 5, while loop finished | |
| 5 | |
| Note that block inside the ``while`` loop, or *body* of the loop is *indented*. | |
| >>> while count < 5: | |
| ... count = count + 1 # hit enter one more time to start the loop | |
| ... | |
| >>> count # when count reached value of 5, while loop finished | |
| 5 | |
| Note that block inside the ``while`` loop, or *body* of the loop is *indented*. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| parentheses ``()``. In simplest form, like ``print(a, b)``, the arguments | ||
| are positional, meaning the function processes them in the same order |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| parentheses ``()``. In simplest form, like ``print(a, b)``, the arguments | |
| are positional, meaning the function processes them in the same order | |
| parentheses ``()``. In its simplest form, like ``print(a, b)``, the arguments | |
| are positional, meaning the function processes them in the same order |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for working on this! As compared to the version on the left hand side, I found presenting all the concepts up front in detailed sections a little intimidating. I preferred seeing the four lines we're building towards first, and then an explanation of what's going on. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The following commit authors need to sign the Contributor License Agreement: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.