#16 · Loops · Intermediate · 55 XP · about 5 min
Write a function called sum_of_digits(n) that returns the sum of all digits in a non-negative integer.
sum_of_digits(123) # Returns 6 (1 + 2 + 3) sum_of_digits(9999) # Returns 36 (9 + 9 + 9 + 9) sum_of_digits(0) # Returns 0 sum_of_digits(7) # Returns 7
First solves only, ranked by stars and then time.