[New-bugs-announce] [issue3490] Example Code Error in Tutorial Documentation

Adam report at bugs.python.org
Sat Aug 2 04:54:19 CEST 2008


New submission from Adam <yoshokun at gmail.com>:

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'
...

----------
assignee: georg.brandl
components: Documentation
messages: 70613
nosy: georg.brandl, yoshokun
severity: normal
status: open
title: Example Code Error in Tutorial Documentation

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3490>
_______________________________________


More information about the New-bugs-announce mailing list