Mercurial > hg > pyloader
comparison tests/objects.py @ 38:f6616a5f468f
test fibonacci sequence
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 07 Jun 2011 19:17:21 -0700 |
parents | 5268ab85fe1b |
children | 49f88cde6219 |
comparison
equal
deleted
inserted
replaced
37:5268ab85fe1b | 38:f6616a5f468f |
---|---|
37 return Wrapper(app) | 37 return Wrapper(app) |
38 | 38 |
39 def fib(n): | 39 def fib(n): |
40 """return the nth fibonacci term""" | 40 """return the nth fibonacci term""" |
41 sequence = [1,1] | 41 sequence = [1,1] |
42 while len(sequence) < n: | 42 while len(sequence) - 1 < n: |
43 sequence.append(sequence[len(sequence)-1], sequence[len(sequence)-2]) | 43 sequence.append(sequence[len(sequence)-1] + sequence[len(sequence)-2]) |
44 return sequence[n] | 44 return sequence[n] |