Interview Query

Digit Accumulator

2
Have you seen this question before?

You are given a string that represents some floating-point number. Write a function, digit_accumulator, that returns the sum of every digit in the string.

Example:

Input:

s = "123.0045"

Output:

def digit_accumulator(s) -> 15

Since 
1 + 2 + 3 + 0 + 0 + 4 + 5 = 15
Next question: Compute Variance
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code