Question: Python 3 Need help debugging my program. The question is given n(string of numbers) and k (integer), multiply n by k and sum the digits
Python 3
Need help debugging my program.
The question is given n(string of numbers) and k (integer), multiply n by k and sum the digits individually until it is one length ( 1-9) and return it by using recursion.
superDigit(n,k) where n='9875' k=4, ==> p=n*k superDigit(p) = superDigit(9875987598759875) 5+7+8+9+5+7+8+9+5+7+8+9+5+7+8+9 = 116 superDigit(p) = superDigit(116) 1+1+6 = 8 superDigit(p) = superDigit(8)
######################################
my program.
def superDigit(n, k): p=n*k def recu(p): if len((p)) == 1: print(p) else: sum=0 for x in p: sum+= +int(x) recu(str(sum)) return recu(p) print(superDigit("9875",4)) OUTPUT:
8 None
QUESTION:
I have use print in the script, but how come the recursion causes a NONE output in the program after the correct output? I don't understand.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
