Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
ds_cs4bd_2324
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s90907
ds_cs4bd_2324
Commits
b63e54f1
Commit
b63e54f1
authored
1 year ago
by
Sven Graupner
Browse files
Options
Downloads
Plain Diff
update assignment D Recursion
parents
6ffc7f9f
797e25dc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
D_recursion/README.md
+7
-5
7 additions, 5 deletions
D_recursion/README.md
D_recursion/recursion.py
+2
-2
2 additions, 2 deletions
D_recursion/recursion.py
with
9 additions
and
7 deletions
D_recursion/README.md
+
7
−
5
View file @
b63e54f1
...
@@ -119,21 +119,23 @@ and each following number is the sum of the two preceding numbers.
...
@@ -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
Fibonacci numbers are widely found in
*nature*
,
*science*
,
*social behaviors*
of
populations and
*arts*
, e.g. they form the basis of the
populations and
*arts*
, e.g. they form the basis of the
[
Golden Ratio
](
https://www.adobe.com/creativecloud/design/discover/golden-ratio.html
)
[
Golden Ratio
](
https://www.adobe.com/creativecloud/design/discover/golden-ratio.html
)
,
in
*painting*
and
*photography*
, see also this
which is widely used
in
*painting*
and
*photography*
, see also this
[
1:32min
](
https://www.youtube.com/watch?v=v6PTrc0z4w4
)
video.
[
1:32min
](
https://www.youtube.com/watch?v=v6PTrc0z4w4
)
video.
<img
src=
"../markup/img/fibonacci.jpg"
alt=
"drawing"
width=
"6
0
0"
/>
<img
src=
"../markup/img/fibonacci.jpg"
alt=
"drawing"
width=
"6
4
0"
/>
<!--  -->
<!--  -->
Complete functions
`fib(n)`
and
`fig_gen(n)`
.
Complete functions
`fib(n)`
and
`fib_gen(n)`
.
```
py
```
py
def
fib
(
self
,
_n
)
->
int
:
def
fib
(
self
,
_n
)
->
int
:
# return value of n-th Fibonacci number
# return value of n-th Fibonacci number
return
#...
return
#...
def
fib_
seq
(
self
,
_n
):
def
fib_
gen
(
self
,
_n
):
# return a generator object that yields two lists, one with n and the
# return a generator object that yields two lists, one with n and the
# other with corresponding fib(n)
# other with corresponding fib(n)
yield
#...
yield
#...
...
...
This diff is collapsed.
Click to expand it.
D_recursion/recursion.py
+
2
−
2
View file @
b63e54f1
...
@@ -30,7 +30,7 @@ class Recursion:
...
@@ -30,7 +30,7 @@ class Recursion:
return
0
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
Return a generator object that yields two lists, one with n and the
other with corresponding fib(n).
other with corresponding fib(n).
...
@@ -152,7 +152,7 @@ if __name__ == '__main__':
...
@@ -152,7 +152,7 @@ if __name__ == '__main__':
# Challenge 2.1, fig_gen()
# Challenge 2.1, fig_gen()
if
21
in
run_choices
:
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
n
,
fib
=
next
(
gen
)
# trigger generator
print
(
f
'
n:
{
n
}
'
)
print
(
f
'
n:
{
n
}
'
)
print
(
f
'
fib(n):
{
fib
}
'
)
print
(
f
'
fib(n):
{
fib
}
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment