classification
Title: Fibonacci example does not include 0; section 4.6
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, mark.dickinson, orsenthil, rajesh.menon, terry.reedy
Priority: critical Keywords:

Created on 2009-11-20 13:50 by rajesh.menon, last changed 2009-11-23 16:43 by mark.dickinson. This issue is now closed.

Messages (7)
msg95542 - (view) Author: Rajesh Menon (rajesh.menon) Date: 2009-11-20 13:50
The example starts off with 1 being printed, while the series is 
expected to begin with 0 and 1.
The example in 4.6 (defining functions) should have been:

def fib(n):
  a, b = 0, 1
  while a < n:
    print a,
    a, b = b, a+b
fib(2000)

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
msg95543 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-11-20 13:55
That depends on whether you want to start the sequence with F_0  (=0) or
F_1 (=1), I guess.  Given Python's general preferences for zero-based
indexing, I agree that this very serious issue should be fixed.

See

http://www.research.att.com/~njas/sequences/A000045

for an authoritative reference.
msg95572 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-11-20 22:02
The delta (patch) is to change 'b' to 'a' in the while and print
statements and prepend '0 ' to the output line.
msg95604 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-11-22 17:37
tjreedy: The reporter's suggestion seems fine. Prepending a 0 does not
seem to be a good idea.
msg95609 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-11-22 22:49
Senthil: look again. The OP's suggestion *is* to prepend a 0 to the current
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
I just specified the delta between current and suggested, should someone
decide to make the change.

That said, def fib2(n), a little further on in 4.6, should get the same
edit as def fib(n) does.
msg95611 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-11-23 00:18
Terry: Oh, sorry. Now I get what you meant by "Prepend O to output
line". That is, Output line from the fib, as part of the patch.  The
changes need to be done at 3 places. Section 3.2, twice in Section 4.6.
msg95637 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-11-23 16:43
Fixed in r76460 through r76463.
History
Date User Action Args
2009-11-23 16:43:27mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg95637

versions: + Python 3.1, Python 2.7, Python 3.2
2009-11-23 00:18:12orsenthilsetmessages: + msg95611
2009-11-22 22:49:24terry.reedysetmessages: + msg95609
2009-11-22 17:37:29orsenthilsetnosy: + orsenthil
messages: + msg95604
2009-11-20 22:02:00terry.reedysetnosy: + terry.reedy
messages: + msg95572
2009-11-20 18:02:15rhettingersetpriority: critical
2009-11-20 13:55:20mark.dickinsonsetnosy: + mark.dickinson
messages: + msg95543
2009-11-20 13:50:30rajesh.menoncreate