How do I write a recursive python function to find factorial of a natural number 6 and a natural number 15?
The following code calculates the factorial for n = 6 and n = 15
def factorial(n): if n == 1: return 1 else: res = n * factorial(n-1) return res print ("factorial(6) = %d" %factorial(6)) print ("factorial(15) = %d" %factorial(15))
We get the output
C:/Users/TutorialsPoint1/~.py factorial(6) = 720 factorial(15) = 1307674368000
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more