Interview Query

Digit Accumulator

Start Timer

0:00:00

Upvote
5
Downvote
Save question
Mark as completed
View comments (16)
Next question

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
.
.
.
.
.


Comments

Loading comments