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)
| 8 | |
| 9 | |
| 10 | def 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 | |
| 29 | if __name__ == "__main__": |