Ask Question
5 April, 01:59

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"

+5
Answers (1)
  1. 5 April, 02:21
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers