def recursive_add(s):
sum = 0
if len(s) == 1:
sum += s[0] ** 2
else:
recursive_add(s[1:])
sum += s[0]**2
return sum
s = [8, 6, 8, 4]
print recursive_add(s)
however, for some reason, 8 gets squared right away and 64 is returned, even though it should be the last number to be squared and added to sum.
1 Answer