This is my code:
def recurSum(x, y):
if x <= 1:
return x
return x + recurSum(x - 1)
if y <= 1:
return y
xxwjhefbhwjbfwjh efjehwbf ebrfe print(recurSum(5, 10))
This is my code:
def recurSum(x, y):
if x <= 1:
return x
return x + recurSum(x - 1)
if y <= 1:
return y
xxwjhefbhwjbfwjh efjehwbf ebrfe print(recurSum(5, 10))
You can use the following:
def recurSum(x, y):
if x==0:
return y
return recurSum(x - 1, y) + x
In essence, the base case is when the first number has reached 0. If so, you return the other number. Otherwise, you perform once again the recursive sum.
This is another way to do this.
def recurSum(x, y):
return y if x < 1 else recurSum(x-1, x + y)
The expanded form of the above is:
def recurSum(x, runningSum):
if x < 1:
return runningSum;
else:
return recurSum(x-1, x + runningSum)
Does the function need to be recursive? I think you might be over complicating this a bit;
def sums(x,y):
output = y + sum(range(0,x+1))
return output
Here in one line you can add the values between 1 and x to y