Recursion in python

Recursion in python

Instructor-svg Al-Mamun Sarkar
Mar 25 , 2020

Use recursion in the python programming language.


def count(i):
    print (i)
    i += 1
    if i == 5:
        return
    count(i)


count(1)


def factorial(number):
    if number == 0:
        return 1
    else:
        return number * factorial(number - 1)


print(factorial(5))

 

Output:

1
2
3
4
120

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram