So here is a code I have which attempts to add every element in a list irrespective of their lengths.
def elem_sum(lst1, lst2):
f_len = len(lst1) - (len(lst2) - 1)
for i in range(0, len(lst2), 1):
if f_len - i >= len(lst1):
break
else:
lst1[i] = lst1[i] + lst2[i]
return lst1
When certain inputs such as elem_sum([1, 2, 3], [10, 20]) are provided,
the output correctly returns [11, 22, 3]
While other inputs such as elem_sum([1, 2, 3], [10, 20, 30, 40])
the output returns error.
What should I change here to make sure my code works for any given set of inputs??