Ask Question
5 September, 07:49

def recursiveDigitSum (n) : ''' Computes the sum of digits of a positive integer n. Returns None of n is negative. - Your solution must use recursion in order to receive credit. ''' return "stub"

+3
Answers (1)
  1. 5 September, 10:54
    0
    def recursiveDigitSum (n):

    if n<10:

    return n

    else:

    return (n%10) + recursiveDigitSum (n/10)

    print (recursiveDigitSum (93))

    Explanation:

    Inside the recursiveDigitSum function, use an if condition to check whether the given number is less than 10. If it's true, return the number as this will act as a stopping criteria. Otherwise, keep on calling the recursiveDigitSum function recursively. Lastly call the recursiveDigitSum function.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “def recursiveDigitSum (n) : ''' Computes the sum of digits of a positive integer n. Returns None of n is negative. - Your solution must use ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers