Returns the sum of the digits in the factorial of num >>> solution(100) 648 >>> solution(50) 216 >>> solution(10) 27 >>> solution(5) 3 >>> solution(3) 6 >>> solution(2) 2 >>> solution(1) 1
(num: int = 100)
| 11 | |
| 12 | |
| 13 | def solution(num: int = 100) -> int: |
| 14 | """Returns the sum of the digits in the factorial of num |
| 15 | >>> solution(100) |
| 16 | 648 |
| 17 | >>> solution(50) |
| 18 | 216 |
| 19 | >>> solution(10) |
| 20 | 27 |
| 21 | >>> solution(5) |
| 22 | 3 |
| 23 | >>> solution(3) |
| 24 | 6 |
| 25 | >>> solution(2) |
| 26 | 2 |
| 27 | >>> solution(1) |
| 28 | 1 |
| 29 | """ |
| 30 | fact = 1 |
| 31 | result = 0 |
| 32 | for i in range(1, num + 1): |
| 33 | fact *= i |
| 34 | |
| 35 | for j in str(fact): |
| 36 | result += int(j) |
| 37 | |
| 38 | return result |
| 39 | |
| 40 | |
| 41 | if __name__ == "__main__": |