Deutsch English |
YOU LEARN HERE... |
that recursion is a solution method in which a problem is traced back to a similar but somewhat simplified problem. A function is recursive if it calls itself. To prevent a recursive function from calling itself endlessly, it needs a termination condition. Consider this chapter as additional material and enjoy the beautiful pictures that are created with recursions. |
EXAMPLES |
Programm: from gturtle import * def step(): forward(20) right(90) forward(20) left(90) def staircase(n): if n == 0: return step() staircase(n-1) staircase(6) |
Programm: from gturtle import * def tree(s): if s < 8: return forward(s) left(45) tree(s/2) right(90) tree(s/2) left(45) back(s) setY(-100) tree(128) Note: the back(s) is important, because after drawing the (partial) tree the turtle must be in the initial state again. |
REMEMBER... |
Recursion is an important solution method in which a problem is reduced to the same, somewhat simplified problem and solved in a particularly simple case (in the case of recursion termination). Recursive solution methods are elegant, but usually difficult to understand. |
OTHER KNOWN RECURSIONS |
Sirpinsky Fractal Flower Fractal Peano Fractal Tree Fractal Koch Fractal |
TO SOLVE BY YOURSELF |
1. |
|
||||
2. |
|
|