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

Function sum_digits

project_euler/problem_065/sol1.py:56–71  ·  view source on GitHub ↗

Returns the sum of every digit in num. >>> sum_digits(1) 1 >>> sum_digits(12345) 15 >>> sum_digits(999001) 28

(num: int)

Source from the content-addressed store, hash-verified

54
55
56def sum_digits(num: int) -> int:
57 """
58 Returns the sum of every digit in num.
59
60 >>> sum_digits(1)
61 1
62 >>> sum_digits(12345)
63 15
64 >>> sum_digits(999001)
65 28
66 """
67 digit_sum = 0
68 while num > 0:
69 digit_sum += num % 10
70 num //= 10
71 return digit_sum
72
73
74def solution(max_n: int = 100) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected