Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help with python ( no loops used please!) Write a recursive function named

ID: 3757349 • Letter: N

Question

need help with python ( no loops used please!)

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

Explanation / Answer

Ans) def sum_digits(n): if n == 0: return 0 else: return sum_digits(n//10) + (n%10)