boris-vlasenko

сумма цифр числа

Sep 25th, 2015
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.18 KB | None | 0 0
  1. # ---- 1 ----
  2. a = input('a=')
  3. s = 0
  4. for x in a:
  5.     s += int(x)
  6. print(s)
  7.  
  8.  
  9. # ---- 2 ----
  10. a = int(input('a='))
  11. s = 0
  12. while a:
  13.     s += a % 10
  14.     a = a // 10
  15. print(s)
Advertisement
Add Comment
Please, Sign In to add comment