-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-107017: Rework the Fibonacci example #107132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
TommyUnreal
wants to merge
17
commits into
python:main
from
TommyUnreal:107017_tutorial_introduction_assumtions_removal_fibonacci
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2383c73
Draft. Rework ´the Fibonacci example.
TommyUnreal f1cd228
Proofread, fixed the PEP 8, doctest.
TommyUnreal 4f8e940
Fix rst formatting and missing literal block
TommyUnreal 2584707
Fix inline literal.
TommyUnreal 1fae12b
Better multichar end arg example in print().
TommyUnreal e87530d
Fix review hints. Explain condition better.
TommyUnreal 10107c1
Fix inline literals.
TommyUnreal cdafb1f
Update Doc/tutorial/introduction.rst
TommyUnreal 3c9bec8
Update Doc/tutorial/introduction.rst
TommyUnreal 6ad0175
Update Doc/tutorial/introduction.rst
TommyUnreal 7722165
Fix multiple assignment example.
TommyUnreal 3c0171e
Corrected grammar errors.
TommyUnreal fbb36a0
Better wording in example comment.
TommyUnreal d9a707d
Fixed typo, improved wording.
TommyUnreal 7e627a4
Fixed missing-space-before-role lint error.
TommyUnreal 33a3b3c
fIXED WARNING: Title underline too short lint.
TommyUnreal 0f51c49
Merge branch 'main' into 107017_tutorial_introduction_assumtions_remo…
hugovk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix review hints. Explain condition better.
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.
- Loading branch information
commit e87530d17a7536cca551789c2cd42a3621956b13
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -389,7 +389,7 @@ Lists | |||||
Python knows a number of *compound* data types, used to group together other | ||||||
values. The most versatile is the *list*, which can be written as a list of | ||||||
comma-separated values (items) between square brackets. Lists might contain | ||||||
items of different types, but usually the items all have the same type. :: | ||||||
items of different types, but usually the items all have the same type:: | ||||||
|
||||||
>>> squares = [1, 4, 9, 16, 25] | ||||||
>>> squares | ||||||
|
@@ -488,7 +488,7 @@ Multiple Assignment | |||||
|
||||||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
expression, it is first evaluated and then assigned.:: | ||||||
expression, it is first evaluated and then assigned:: | ||||||
|
||||||
>>> a, b = 1, 5 # multiple assignment of two variables | ||||||
>>> a | ||||||
|
@@ -505,10 +505,10 @@ Repeating our code | |||||
------------------ | ||||||
|
||||||
The :keyword:`while` loop is example of a repeating cycle. It performs | ||||||
TommyUnreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
a block of code over as long as the condition (in example: ``a < 10``) is | ||||||
a block of code over as long as the condition is | ||||||
TommyUnreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
fulfilled. The test used in the example is a simple comparison you might | ||||||
know from arithmetics. Fulfilled condition have the value True. Unfulfilled | ||||||
condition have the value False.:: | ||||||
know from arithmetics. Fulfilled condition have the value ``True``. | ||||||
TommyUnreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Unfulfilled condition have the value ``False``:: | ||||||
TommyUnreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
>>> 1 < 3 # 1 is less than 3 | ||||||
True | ||||||
|
@@ -526,21 +526,26 @@ In Python, the following comparison operators are used: | |||||
* ``>=``: Greater than or equal to | ||||||
* ``!=``: Not equal to | ||||||
|
||||||
:: | ||||||
Let's create a simple loop. We need the keyword ``while`` and a condition; | ||||||
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 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
>>> 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*. | ||||||
Note that block inside the `while` loop, or *body* of the loop is *indented*. | ||||||
Indentation is Python's way of grouping statements together. When you use | ||||||
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 | ||||||
we have finished typing the last line).:: | ||||||
follow it by a blank line to indicate its completion. This way, the parser | ||||||
knows we have finished typing the last line):: | ||||||
|
||||||
>>> number = 1 | ||||||
>>> while number < 5: | ||||||
|
@@ -559,7 +564,7 @@ We already know :func:`print` function, that writes the value of the | |||||
argument(s) it receives on screen. The arguments are enclosed within | ||||||
parentheses ``()``. In simplest form, like ``print(a, b)`` the arguments | ||||||
are positional, meaning the function processes them in the same order | ||||||
as they are written.:: | ||||||
as they are written:: | ||||||
|
||||||
>>> group = "Knights" | ||||||
>>> say_what = '"Ni!"' | ||||||
|
@@ -582,7 +587,7 @@ Fibonacci series | |||||
---------------- | ||||||
|
||||||
Great! Now that we have the knowledge, let's write code to print all numbers | ||||||
from the Fibonacci series that are lower than 150. | ||||||
from the Fibonacci series that are lower than 150:: | ||||||
|
||||||
>>> a, b = 0, 1 | ||||||
>>> while a < 150: | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment 10000 to others. Learn more.