English

How to set the limit for recursive function? Give an example.

Advertisements

Question

How to set the limit for recursive function? Give an example.

Short/Brief Note
Advertisements

Solution

Python also allows you to change the limit using sys.setrecursionlimit (limit value).

Example:

import sys
sys.setrecursionlimit(3000)
def fact (n):
if n = = 0:
return 1
else:
return n * fact (n – 1)
print (fact (2000))

shaalaa.com
Introduction to Python Functions
  Is there an error in this question or solution?
Chapter 7: Python functions - Evaluation [Page 112]
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×