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

12th Jun 2017, 9:21 AM
lars
3 ответов
+ 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
12th Jun 2017, 10:40 AM
yuri
+ 1
in Pythonic way it is to be : sum(k for k in range(n+1))
12th Jun 2017, 10:48 AM
yuri
0
def fun_sumton(n): if n==0: return 0 else: fun_sumton(n-1)
12th Jun 2017, 12:17 PM
Shashank
Shashank - avatar