MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / digit_sum

Function digit_sum

project_euler/problem_119/sol1.py:16–26  ·  view source on GitHub ↗

Returns the sum of the digits of the number. >>> digit_sum(123) 6 >>> digit_sum(456) 15 >>> digit_sum(78910) 25

(n: int)

Source from the content-addressed store, hash-verified

14
15
16def digit_sum(n: int) -> int:
17 """
18 Returns the sum of the digits of the number.
19 >>> digit_sum(123)
20 6
21 >>> digit_sum(456)
22 15
23 >>> digit_sum(78910)
24 25
25 """
26 return sum(int(digit) for digit in str(n))
27
28
29def solution(n: int = 30) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected