Ask Question

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. 6 January, 21:17
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers