I have encountered a problem where a return
gives None
back, though the variable had a value just a single line of code before.
mylist = [[7]]
def sumcalc(the_list,n):
s = n
for x,y in enumerate(the_list):
if type(y) == list:
sumcalc(y,s)
elif type(y) == int:
s += y
if x < len(the_list)-1:
sumcalc(the_list[x+1], s)
else:
print (s)
return s
print(sumcalc(mylist,0))
The print command in the second to last line gives me 7, as expected. But the return is None
. Any help on this would be appreciated :)