This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Example Code Error in Tutorial Documentation Section 4.4
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: benjamin.peterson, georg.brandl, yoshokun
Priority: normal Keywords:

Created on 2008-08-02 02:54 by yoshokun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg70613 - (view) Author: Adam (yoshokun) Date: 2008-08-02 02:54
In section 4.4 of the Python Tutorial
(http://docs.python.org/tut/node6.html) there is a code example using
prime numbers that results extraneous output. The else is incorrectly
indented one tab too far to the right and is nested under (for x in
range) rather than (for n in range).

Current:

>>> for n in range(2, 10):
...     for x in range(2, n):
...         if n % x == 0:
...             print n, 'equals', x, '*', n/x
...             break
...     else:
...         # loop fell through without finding a factor
...         print n, 'is a prime number'
... 

Correct:

>>> for n in range(2, 10):
...     for x in range(2, n):
...         if n % x == 0:
...             print n, 'equals', x, '*', n/x
...             break
...  else:
...      # loop fell through without finding a factor
...      print n, 'is a prime number'
...
msg70614 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-02 02:57
Thanks! Fixed in r65382.
msg70616 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-02 03:02
Sorry, the example actually is correct. (reverted)
msg70627 - (view) Author: Adam (yoshokun) Date: 2008-08-02 12:01
You know what, you're absolutely right. My apologies for sending the bad
submission. =\
History
Date User Action Args
2022-04-11 14:56:37adminsetgithub: 47740
2020-05-14 05:49:36Chas Belovsettitle: Example Code Error in Tutorial Documentation -> Example Code Error in Tutorial Documentation Section 4.4
2008-08-02 12:01:47yoshokunsetmessages: + msg70627
2008-08-02 03:02:02benjamin.petersonsetresolution: fixed -> rejected
messages: + msg70616
2008-08-02 02:57:30benjamin.petersonsetstatus: open -> closed
nosy: + benjamin.peterson
resolution: fixed
messages: + msg70614
2008-08-02 02:54:18yoshokuncreate