Skip to content
Snippets Groups Projects
Commit b63e54f1 authored by Sven Graupner's avatar Sven Graupner
Browse files

update assignment D Recursion

parents 6ffc7f9f 797e25dc
No related branches found
No related tags found
No related merge requests found
......@@ -119,21 +119,23 @@ and each following number is the sum of the two preceding numbers.
Fibonacci numbers are widely found in *nature*, *science*, *social behaviors* of
populations and *arts*, e.g. they form the basis of the
[Golden Ratio](https://www.adobe.com/creativecloud/design/discover/golden-ratio.html)
in *painting* and *photography*, see also this
[Golden Ratio](https://www.adobe.com/creativecloud/design/discover/golden-ratio.html),
which is widely used in *painting* and *photography*, see also this
[1:32min](https://www.youtube.com/watch?v=v6PTrc0z4w4) video.
<img src="../markup/img/fibonacci.jpg" alt="drawing" width="600"/>
<img src="../markup/img/fibonacci.jpg" alt="drawing" width="640"/>
<!-- ![image](../markup/img/fibonacci.jpg) -->
Complete functions `fib(n)` and `fig_gen(n)`.
&nbsp;
Complete functions `fib(n)` and `fib_gen(n)`.
```py
def fib(self, _n) -> int:
# return value of n-th Fibonacci number
return #...
def fib_seq(self, _n):
def fib_gen(self, _n):
# return a generator object that yields two lists, one with n and the
# other with corresponding fib(n)
yield #...
......
......@@ -30,7 +30,7 @@ class Recursion:
return 0
def fib_seq(self, _n):
def fib_gen(self, _n):
"""
Return a generator object that yields two lists, one with n and the
other with corresponding fib(n).
......@@ -152,7 +152,7 @@ if __name__ == '__main__':
# Challenge 2.1, fig_gen()
if 21 in run_choices:
gen = n1.fib_seq(20) # yield generator object
gen = n1.fib_gen(20) # yield generator object
n, fib = next(gen) # trigger generator
print(f'n: {n}')
print(f'fib(n): {fib}')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment