[docs] Error in The Python Tutorial
Sandro Tosi
sandro.tosi at gmail.com
Sun Apr 3 15:17:49 CEST 2011
Hi Dhaval,
thanks for your email.
On Mon, Mar 28, 2011 at 01:15, Dhaval Patel <dh.electro at gmail.com> wrote:
> Hi
>
> I am learning Python. As a part of my learning process, I found your
> tutorial very helpful.
>
> Today I have found error in section
>
> 4.4. break and continue Statements, and else Clauses on Loops
>
>>>> 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'
> ...
> 2 is a prime number
> 3 is a prime number
> 4 equals 2 * 2
> 5 is a prime number
> 6 equals 2 * 3
> 7 is a prime number
> 8 equals 2 * 4
> 9 equals 3 * 3
>
>
>
> The first output
> 2 is a prime number is not coming out
do you mean this is not coming out when you're trying on your python
shell? what version of python are you using?
> I think when it goes in first inner for loop for x in range(2,2):
> range (2,2) is []
and that's correct, since it has to go into the 'else' branch.
> so it is not printing
> 2 is a prime number is not coming out
>
> I just want to make sure it my understanding is correct or there is mistake
> in document.
The doc is correct: I tried several times and it works as expected,
pay attention to the indentation of 'else' below the inner for loop.
Don't hesitate to ask further in case it's not clear enough.
Regards,
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
More information about the docs
mailing list