maximum recursion depth exceeded in comparison

后端 未结 6 1914
故里飘歌
故里飘歌 2021-01-06 13:21

I wrote this piece of code to compute the number of combinations:

def fact(n):
    return 1 if(n == 1) else n * fact(n - 1)

def combinations(n,k):
    retur         


        
6条回答
  •  心在旅途
    2021-01-06 14:03

    The default recursion limit in python 3.x version onwards is 2000 only, If you call the same function again and again more than 2000 times, you will get maximum recursion depth error. The ideal approach would be to write a logic without recursion. But If you still stick to recursion, change the default recursion limit by:

    import sys

    sys.setrecursionlimit(10000)# It sets recursion limit to 10000.

    But the above may not meet all your needs in certain contexts.

提交回复
热议问题