Verified Commit 56b2177c authored by Bertrand  NÉRON's avatar Bertrand NÉRON
Browse files

propose a second implementation

parent 2d2a2a71
def fibonacci(n):
"""
compute the suite of fibonacci for n element and return it
for instance ::
fibonacci(7)
[0, 1, 1, 2, 3, 5, 8, 13, 21]
:param int n: the nth elemnt of the fibonacci suite
:return: the nfirst elt of the fibonacci suite
:rtype: list of int
"""
fib_suite = []
i = 0
while i <= n:
......@@ -16,3 +27,16 @@ def fibonacci(n):
print ', '.join([str(i) for i in fibonacci(10)])
def fibonacci_2(n):
"""
compute the fibonacci of the elt n
:param int n:
:return: the fibonacci of the elt n
:rtype: int
"""
a = 0
b = 1
for i in range(n):
a, b = b, a + b
return b
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment