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 function # 4.4 is incorrect
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: fdrake Nosy List: fdrake
Priority: normal Keywords:

Created on 2001-05-16 15:11 by anonymous, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (3)
msg4775 - (view) Author: Nobody/Anonymous (nobody) Date: 2001-05-16 15:11
(Refers to the online tutorial at 
http://www.python.org/doc/current/tut/node6.html#SECTIO
N006400000000000000000)

The code should be changed to:

>>> for n in range(2, 10):
...     for x in range(2, n):
...         if n % x == 0:
...             print n, 'equals', x, '*', n/x
...             break 
...         elif x < (n-1) :
...             continue # keep checking
...         else:
...             print n, 'is a prime number'



Otherwise, you will get multiple "7 is a prime number" 
statements with the current code. Also, if would 
incorrectly say "9 is a prime number" and "9 equals 3 
* 3". I added the elif/continue part to take care of 
these two problems.

msg4776 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2001-05-16 15:41
Logged In: YES 
user_id=3066

I'll add a comment to the "else" clause of the for loop in  a future checkin, but the code is correct.

(The submitter admitted he made an indentation error in a followup email.)
msg4777 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2001-05-21 16:57
Logged In: YES 
user_id=3066

Checked in as part of Doc/tut/tut.tex revision 1.135.
History
Date User Action Args
2022-04-10 16:04:03adminsetgithub: 34509
2001-05-16 15:11:08anonymouscreate