0

my recursive function is in RecursionError when being called by my tempsExecution2 function in the times i use more than 2 ceros for the quantity. I dont know why this happends nor how to fix it and i would like to test big numbers of operations.

#  1 -RECURSIVE FUNCTION 
def sommeRec(n):
    if n == 0: #cas de base  #ERROR line
       return 0
    else: 
      if n > 0:
        return sommeRec(n-1) + n  #appel recursive
print(sommeRec(3))
def tempsExecution2(n,f):
    start=time()
    f(n)               
    end=time()
    return end-start
print("le temps d'exe de sommeRec est: ")
print(tempsExecution2(2000,sommeRec))  
def tempsExecution2(n,f):
    start=time()
    f(n)               
    end=time()
    return end-start
print("le temps d'exe de sommeRec est: ")
print(tempsExecution2(200,sommeRec)) #why cant i use bigger numbers?
Axq
  • 1
  • 2
  • Python doesn't support arbitrarily deep recursion. The default recursion limit is around 1000. There are ways to increase this limit, but why bother? Learn to write idiomatic Python code instead. Outside of explicit or implicit tree traversal, recursion is rarely used in Python. – John Coleman Oct 26 '22 at 00:48
  • You might find [this other SO Question](https://stackoverflow.com/q/3323001/289011) interesting. – Savir Oct 26 '22 at 00:49

0 Answers0