Question

Write a recursive function named sum_digits that takes a given a non-negative integer N and returns the sum of its digits. Hint: Mod (%) by 10 gives you the rightmost digit (126 % 10 is 6), while doing integer division by 10 removes the rightmost digit (126/10 is 12). This function has to be recursive; you are not allowed to use loops to solve this problem! This function takes in one integer and returns one intege. For example: Test Result print (234, : , sum_digits (234)) 234: 9

need help with python ( no loops used please!)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Ans)
def sum_digits(n):
    if n == 0:
        return 0
    else:
        return sum_digits(n//10) + (n%10)
Add a comment
Know the answer?
Add Answer to:
need help with python ( no loops used please!) Write a recursive function named sum_digits that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT