Consider this one .
More seriously ...
Recursion is a way to solve problems that have a well-defined underlying case (or cases, btu, I make it simple here.)
As an example, the often mentioned factor problem is a big one.
What does factorial do? Let's look at some examples:
factorial(0) = 1
factorial(1) = 1
factorial(2) = 2
factorial(3) = 6
factorial(4) = 24
- , , , ( ) 0. 0 1. ( , .)
, . , , ( , .) .
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x-1)
,
- , Google .