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

Function solution

project_euler/problem_020/sol4.py:13–38  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

11
12
13def 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
41if __name__ == "__main__":

Callers 1

sol4.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected