Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub-courses
python_one_week_4_biologists_solutions
Commits
56b2177c
Verified
Commit
56b2177c
authored
Mar 11, 2019
by
Bertrand NÉRON
Browse files
propose a second implementation
parent
2d2a2a71
Changes
1
Hide whitespace changes
Inline
Side-by-side
source/_static/code/fibonacci_iteration.py
View file @
56b2177c
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment