14th, February, 2020
A Recursive function means a function whose definition contains a function call to a function call to itself.
def fact(c):
if c == 0:
return 1
else:
return c * fact(c-1)
c = int(input("Enter a number to calculate the factorial: "))
print("Factorial: ",fact(c))
This function is recursive as in the else statement it calls upon the function once more meaning that another function is being executed in that position of the original function until the first if selection is completed within the recursive function.
Recursive functions often require a lot less code, however are a lot more difficult to understand. Every time a function call is a new block of memory allocated to the function so too many of these calls within each other can mean a recursive function can lead to memory overflows.