def spynum (n,r,sm=0,pd=1):
#s = 0
#p = 1
#b = False
if n == 0:
print (sm==pd)
return sm == pd
else:
rem = n % 10
sm += rem
pd *= rem
print (sm,pd,rem)
spynum(n//10,rem,sm,pd)
num = 1124
print (spynum(num,num%10,0,1))
The program returns Boolean also working if I print the variable inside base condition but it is not print the same outside the function.Im really confused ABT it !
spynumfrom insidespynumfrom insidespynum... and so on. At some point the last invocation finds that n == 0 and returns a boolean. That boolean is returned to the invocation before it, which simply ignores it, not to the main program. You need to propagate the answer back through your chain ofspynuminvocations, all the way to the top and the main program. It's probably just a one-word change: addreturnbefore the recursive invocation ofspynum.