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

Function solution

project_euler/problem_016/sol1.py:10–29  ·  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 >>> solution(1000)
13 1366
14 >>> solution(50)
15 76
16 >>> solution(20)
17 31
18 >>> solution(15)
19 26
20 """
21 num = 2**power
22 string_num = str(num)
23 list_num = list(string_num)
24 sum_of_num = 0
25
26 for i in list_num:
27 sum_of_num += int(i)
28
29 return sum_of_num
30
31
32if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected