Sometimes we will be coding a fucntion that need to be more than one time. So we will be facing a problem since mayve we would be able to solve our problem by making our algorithm longer but at the end thats not how we should learn to program. We should learn how to be efficient and fast, so we must learn what recursion means which is just what we need in cases like this.

A recursion allow a function to be written inside itself so it can run more than one time. The function would be running itself.

A lot of information about recursion states that knowing how to create a program that gets you the factorial number is an awesome begining to understand recursion.

The code would be like this.

def factorial(a):

if a == 1:

return 1

return (a*factorial(a-1))

We can see how at the last line the programm compute the function inside the function. The programm would do something like

5! = 4 * 3 * 2 * 1

and this will make it faster and more efficient

CC BY 4.0 Recursion for repetitive algorithms by fersabal is licensed under a Creative Commons Attribution 4.0 International License.