I want to use recursion to calculate the sum of the list values, but there is an error when using the sum2 function: TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
def sum(list):
if list == []:
return 0
else:
return list[0] + sum(list[1:])
print(sum([1,2,3]))
def sum2(list):
if list == []:
return 0
else:
print(list[0] + sum(list[1:]))
sum([1,2,3])