I need to define a function that finds the numbers within a list that add up to a given sum. I want to do this function recursively.
This is what I have so far, I think I need to work on my recursion and base cases.
def findsum ( x , y ) :
pile = []
z = x-y[0]
if x == 0 :
return pile
elif y == [] :
return pile
else:
index = 0
n = len ( y )
while index < n:
if sum( y[:index]) == x - y[index]:
pile += y[index]
y = y[:index]
x = x - y[index]
index += 1
return pile + findsum ( x , y )
How can I edit this to find the the numbers in list y that add up to the sum x while using recursion.