Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to sum digits of a number in python

number = 123 # the number you want summed up
sum_of_digits = 0 
for digit in str(number):
  sum_of_digits += int(digit)
  
print(sum_of_digits) # printing the final sum of number
Source by kite.com #
 
PREVIOUS NEXT
Tagged: #sum #digits #number #python
ADD COMMENT
Topic
Name
9+8 =