Posts

Showing posts from July, 2019
RECURSION PROBLEMS

Python Recursive Function

Image
RECURSIVE FUNCTION A  function  can call other functions. It is even possible for the function to call itself. These type of construct are termed as recursive functions. Factorial of a number is the product of all the integers from 1 to that number. For example, the factorial of 6 (denoted as 6!) is 1*2*3*4*5*6 = 720. # An example of a recursive function to # find the factorial of a number def calc_factorial(x):     """This is a recursive function     to find the factorial of an integer"""     if x == 1:         return 1     else:         return (x * calc_factorial(x-1)) num = 4 print("The factorial of", num, "is", calc_factorial(num) EXPLANATION In the above example,  calc_factorial()  is a recursive functions as it calls itself. When we call this function with a positive integer, it will recursively call itself by decreasing the number. Each function ca...