Answers:
Depth of recursion: Number of times a function is called recursively.
Example: Consider a program to compute the factorial of a number using a recursion. When given a large input, the program crashed and gives a "maximum recursion of depth exceeded error".
# A simple recursive function
# to compute the factorial of a number
def fact(n):
if(n == 0):
return 1
return n * fact(n - 1)
if __name__ == '__main__':
# taking input
f = int(input('Enter the number: \n'))
print(fact(f))
You can check the recursion limit with sys.getrecursionlimitand change the recursion limit with sys.setrecursionlimitbut doing so is dangerous. The standard limit is a little conservative, but Python stackframes can be quite big.
Login to add comment