Reference no: EM132183933
Define a function named add_from_one_again(st) which receives a list containing digits only (at least one digit, and all digits >0, no need to validate) and returns a number as illustrated by the following examples
When the list is
[5,2,3]
the resulting number should be:
(1+2+3+4+5) + (1+2) + (1+2+3) = 24
When the list is
[3,2,5]
the resulting number should be:
(1+2+3) + (1+2) + (1+2+3+4+5) = 24
When the list is
[4,2,2]
the resulting number should be:
(1+2+3+4) + (1+2) + (1+2) = 16
As an example, the following code fragment:
lst = [5,2,3]
print(add_from_one_again(lst))
should produce the output:
24
Language: python
I have this so far, but doesn't work:
def add_from_one_again(st):
collect_sum = 0
for i in st:
i = int(i)
collect_sum += sum(len(i))
return collect_sum