File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ n! means n × (n − 1) × ... × 3 × 2 × 1
3
+
4
+ For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
5
+ and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
6
+
7
+ Find the sum of the digits in the number 100!
8
+ """
9
+
10
+
11
+ def solution (n ):
12
+ """Returns the sum of the digits in the number 100!
13
+ >>> solution(100)
14
+ 648
15
+ >>> solution(50)
16
+ 216
17
+ >>> solution(10)
18
+ 27
19
+ >>> solution(5)
20
+ 3
21
+ >>> solution(3)
22
+ 6
23
+ >>> solution(2)
24
+ 2
25
+ >>> solution(1)
26
+ 1
27
+ """
28
+ fact = 1
29
+ result = 0
30
+ for i in range (1 ,n + 1 ):
31
+ fact *= i
32
+
33
+ for j in str (fact ):
34
+ result += int (j )
35
+
36
+ return result
37
+
38
+
39
+ if __name__ == "__main__" :
40
+ print (solution (int (input ("Enter the Number: " ).strip ())))
You can’t perform that action at this time.
0 commit comments