I have these two lists of integer:
A=[1,5,3]
B=[4,5,9,8]
I want to use the recursive method o get the sum of these two , and extra integer just appends to the result. So I should get:
[5,10,12,8]
Here are my functions:
def sum(A,B):
a = len(A)
b = len(B)
if a == 0 :
return B
elif b == 0 :
return A
elif a >= b :
return A[0] + B[0] + sum(A[1:b],B[1:])+ **list1[(b+1):]**
else:
return A[0] +B[0] + sum(A[1:],B[1:a])+**list2[(a+1):]**
For the "****" bold part, i am not sure whether i am correct or not, and furthermore, when i ran the program, i got "return A[0] + B[0] + sum(A[1:b],B[1:])+A[(b+1):]
TypeError: unsupported operand type(s) for +: 'int' and 'list'"