def recursiveSum(lst):
if len(lst) == 0:
return 0
else:
#print(str(type(lst))+'\n')
num = lst[len(lst)-1]
return recursiveSum(lst.pop()) + num
size = int(input("How many number do you want to enter? = "))
lst=[]
for i in range(size):
lst.append(input("Enter number "+str(i+1)+" = " ))
print(recursiveSum(lst))
In this code i am trying to find sum of list of numbers recursively , this is my first attempt with recursions , i think my approach and algorithm was correct , the list when passed to the recursiveSum() function somehow makes it string in the else part , the commented line when executed ends up printing
class 'list'
class 'str'
I don't understand how the print statement prints both list and str.
Can someone explain this ?