Skip to content

Latest commit

 

History

History
61 lines (36 loc) · 1012 Bytes

Get_recursion_limit.md

File metadata and controls

61 lines (36 loc) · 1012 Bytes

CodeWars Python Solutions


Get recursion limit

Description

In the sys module there is a function sys.setrecursionlimit and sys.getrecursionlimit. These two functions set and get the recursion limit. If function calls stack is larger than this limit it will raise a RuntimeError

Examples of these two functions:

import sys
sys.setrecursionlimit(905)
sys.getrecursionlimit() # returns 905
sys.setrecursionlimit(89)
sys.getrecursionlimit() # returns 89

Task

Write a function fetch_recursion_limit that acts the same as sys.getrecursionlimit without importing any libraries.

10 >= Recursion Limit <= 15000

Hint: Write a separate recursive function


Given Code

def fetch_recursion_limit():
    pass

Solution

def fetch_recursion_limit():
    try:
        return fetch_recursion_limit() + 1
    except:
        return 2

See on CodeWars.com