Find the sum of digits of a number >>> sum_of_digits_compact(12345) 15 >>> sum_of_digits_compact(123) 6 >>> sum_of_digits_compact(-123) 6 >>> sum_of_digits_compact(0) 0
(n: int)
| 35 | |
| 36 | |
| 37 | def sum_of_digits_compact(n: int) -> int: |
| 38 | """ |
| 39 | Find the sum of digits of a number |
| 40 | >>> sum_of_digits_compact(12345) |
| 41 | 15 |
| 42 | >>> sum_of_digits_compact(123) |
| 43 | 6 |
| 44 | >>> sum_of_digits_compact(-123) |
| 45 | 6 |
| 46 | >>> sum_of_digits_compact(0) |
| 47 | 0 |
| 48 | """ |
| 49 | return sum(int(c) for c in str(abs(n))) |
| 50 | |
| 51 | |
| 52 | def benchmark() -> None: |
nothing calls this directly
no outgoing calls
no test coverage detected