[docs] Bugs in Tutorial for Python 3.6.2. Section 4.4 (p. 19)
Hendra Soetjahja
hendras at yahoo.com
Wed Jul 26 19:39:35 EDT 2017
Hi Python Development Team,
There are 3 bugs in Tutorial for Python 3.6.2. Section 4.4 (p. 19).
These are tested for both in Python 2.7, 3.5, and 3.6 interpreters, as module and in interactive mode.I also tested it on Ubuntu 16.04 LTS, Windows 7, and Windows 10.
The bugs are:
(1) I don't know how you could get number 2 printed out as prime number since is when n=2 and x=2 the condition is FALSE for x inrange(2, n):range is always 'less than' not 'less than and equal to'. So for n=2 and x=2 case (ie. evaluation of number 2), it never enter the for loop to be evaluated.In other words, number 2 never gets evaluated, hence could never be printed either as prime number or not.
(2) Even if it does enter into the for loop by changing it the upper limit of range to range (2, n+1), as for x inrange(2, n+1):Number to would be considered as non-prime since 2%2 is 0 the first time it runs and it would never get into the prime number section since it breaks out of the for loop.
(3) Python also claims that 9 to be both prime number when 9%2 and not prime number when 9 % 3 is 0.
for n in range(2, 10): for x inrange(2, n): # equivalent to (2, 1) = FALSE condition, while evaluating number 2
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')
Output claims in the document:
2 is a prime number3 is a prime number4 equals 2 * 25 is a prime number6 equals 2 * 37 is a prime number8 equals 2 * 49 equals 3 * 3 ----------------------------------------------------------------------------------
This message with its attachment(s) are confidential, restricted, proprietary, and only for the originally addressed recipient(s). If you are not among the intended recipient(s), you are obligated to destroy this message immediately without using, sharing, disclosing, copying, distributing, or archiving it. Anyone acting otherwise will be responsible for any ramification that may arise from the unauthorized usage or distribution of this message. The sender is not liable for any loss or damage arising in any way from this message or its attachment(s). By messaging with the sender you consent to the aforementioned terms.
----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20170726/d4819a09/attachment.html>
More information about the docs
mailing list