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

Function solution

project_euler/problem_016/sol2.py:10–26  ·  view source on GitHub ↗

Returns the sum of the digits of the number 2^power. >>> solution(1000) 1366 >>> solution(50) 76 >>> solution(20) 31 >>> solution(15) 26

(power: int = 1000)

Source from the content-addressed store, hash-verified

8
9
10def solution(power: int = 1000) -> int:
11 """Returns the sum of the digits of the number 2^power.
12
13 >>> solution(1000)
14 1366
15 >>> solution(50)
16 76
17 >>> solution(20)
18 31
19 >>> solution(15)
20 26
21 """
22 n = 2**power
23 r = 0
24 while n:
25 r, n = r + n % 10, n // 10
26 return r
27
28
29if __name__ == "__main__":

Callers 1

sol2.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected