0
How to create a sum integers with a recursive funktion in python?
Sorry I'm not good in Math a=0 c=0 Def sum_rek (n) for i in range (1,1+n//2): a+=1 n-=1 b=a+n d=1 +(b*n//2) print (d) sum_rek (10) Where's my mistake? Output should look be 55
3 odpowiedzi
+ 1
I hate recursions. you need to specify "exit" condition first!!! that is a key in any recursion. see the code
https://code.sololearn.com/cWS00y4S2CMP/?ref=app
+ 1
in Pythonic way it is to be :
sum(k for k in range(n+1))
0
def fun_sumton(n):
if n==0:
return 0
else:
fun_sumton(n-1)