Problem 146901 · easy · Phase 01 Prerequisites & Setup

Sum of the Digits

functions · digits · loops

Write digit_sum(n) that returns the sum of the decimal digits of the integer n. Ignore the sign: the digits of -905 are 9, 0, 5.

Examples

Input:  n = 1234
Output: 10

Input:  n = -905
Output: 14

Input:  n = 0
Output: 0

Constraints

  • -10**18 <= n <= 10**18

Goals

  • Peel off digits with `% 10` and `// 10`
  • Handle zero and negative inputs
Starting Python…