maximum recursion depth exceeded in comparison

后端 未结 6 1941
故里飘歌
故里飘歌 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:12

    something like this works well:

    def factorial_by_recursion(max_number, current_number, somme):
        if current_number < max_number:
            somme += current_number
            return factorial_by_recursion(max_number, current_number + 1, somme)
        else:
            return somme
    

提交回复
热议问题