...

/

Solution Review: Sum of Digits in a String

Solution Review: Sum of Digits in a String

This review provides a detailed analysis of the solution to find the sum of digits in a string

We'll cover the following...

Solution: Using Recursion

Press + to interact
def sumDigits(testVariable):
# Base Case
if testVariable == "":
return 0
# Recursive Case
else:
return int(testVariable[0]) + sumDigits(testVariable[1:])
# Driver Code
print(sumDigits("345"))

Explanation

The solution to this problem is similar to the solution of finding the length of a string.

For this problem, we remove ...