You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error in Python tutorial (http://docs.python.org/tut/node6.html) #46976
Section 4.4 on page http://docs.python.org/tut/node6.html has a for loop
which uses the range function. However, the displayed output of that
loop is not correct. I ran the same code and got the output as follows:
3 is a prime number
4 = 2 * 2
5 is a prime number
5 is a prime number
5 is a prime number
6 = 2 * 3
7 is a prime number
7 is a prime number
7 is a prime number
7 is a prime number
7 is a prime number
8 = 2 * 4
9 is a prime number
9 = 3 * 3
Can this be corrected in the tutorial as it can be confusing for a
python newbie!
Activity
sandeepsabnani commentedon Apr 30, 2008
Section 4.4 on page http://docs.python.org/tut/node6.html has a for loop
which uses the range function. However, the displayed output of that
loop is not correct. I ran the same code and got the output as follows:
3 is a prime number
4 = 2 * 2
5 is a prime number
5 is a prime number
5 is a prime number
6 = 2 * 3
7 is a prime number
7 is a prime number
7 is a prime number
7 is a prime number
7 is a prime number
8 = 2 * 4
9 is a prime number
9 = 3 * 3
Can this be corrected in the tutorial as it can be confusing for a
python newbie!
Thanks!
amauryfa commentedon Apr 30, 2008
No, the example is correct, and gives the expected output.
From the output you show, I suppose that you indented the "else:" clause
incorrectly: it should align with the "for" loop, not the "if" statement.
The "for...else.." construct is precisely the point of this paragraph.
sandeepsabnani commentedon Apr 30, 2008
Oh yes! Thanks for clearing my doubt and apologies for the silly error.