Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

adding integers from a string python

#prints the sum of any number 
def sum_of_digits(nums: int):
    nums=str(nums)
    sum = 0
    for i in nums:
        sum+=int(i)
    return sum

print(sum_of_digits(123))

#prints '6'. 1+2+3
 
PREVIOUS NEXT
Tagged: #adding #integers #string #python
ADD COMMENT
Topic
Name
6+2 =