Loading...
Loading...
Loading...
A checksum adds up the digits of an account number. Write digit_sum(n) that returns the sum of the digits of n and print it.
Example
Input
4821
Output
15
4 + 8 + 2 + 1.
Try the problem first. Open one hint at a time.
n % 10 is the last digit and n // 10 removes it.
Loop while n is greater than 0 and add each last digit to a total.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor