This is CsCircles, section 16:Recursion, Excercise: digital root This is CsCircl
ID: 3779289 • Letter: T
Question
This is CsCircles, section 16:Recursion, Excercise: digital root This is CsCircles, section 16:Recursion, Excercise: digital rootPython language
Now you will write a recursive function that calls digitalSum as a subroutine. coding Exercise: Digital Root The digital root of a non-negative integer n is computed as follows. Begin by summing the digits of n. The digits of the resulting number are then summed, and this process is continued until a single-digit number is obtained For example, the digital root of 2019 is 3 because and 1+2-3. write a recursive function digitalRootCn) which returns the digital root of n Assume that a working definition of digitalsum will be provided for your program. Run program Enter test statements Open in console Visualize More actions... Did not pass tests. Please check details below and try again. Reinna n inninn
Explanation / Answer
main.py
def digitalSum(n, summ=0):
if n < 10:
summ += n
return summ
else:
summ += (n % 10)
#print ('the sum is:', summ)
n = (n//10)
return (digitalSum(n, summ))
def digitalRoot(n):
result = digitalSum(n)
if result == 10 or result > 10 :
return digitalRoot(digitalSum(result))
else:
return result
print (digitalRoot(99999999999199999999999))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.