Python :Sum of digits eg#3


SUBMITTED BY: Guest

DATE: Dec. 16, 2013, 8:43 a.m.

FORMAT: Python

SIZE: 163 Bytes

HITS: 900

  1. # find sum of digits
  2. n = input("enter an integer : ")
  3. total = 0
  4. for i in n : # string is iterable
  5. # print(i)
  6. total += int(i)
  7. print(total)

comments powered by Disqus