MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / digit_factorial_sum

Function digit_factorial_sum

project_euler/problem_074/sol2.py:42–69  ·  view source on GitHub ↗

Function to perform the sum of the factorial of all the digits in number >>> digit_factorial_sum(69.0) Traceback (most recent call last): ... TypeError: Parameter number must be int >>> digit_factorial_sum(-1) Traceback (most recent call last): ... Valu

(number: int)

Source from the content-addressed store, hash-verified

40
41
42def digit_factorial_sum(number: int) -> int:
43 """
44 Function to perform the sum of the factorial of all the digits in number
45
46 >>> digit_factorial_sum(69.0)
47 Traceback (most recent call last):
48 ...
49 TypeError: Parameter number must be int
50
51 >>> digit_factorial_sum(-1)
52 Traceback (most recent call last):
53 ...
54 ValueError: Parameter number must be greater than or equal to 0
55
56 >>> digit_factorial_sum(0)
57 1
58
59 >>> digit_factorial_sum(69)
60 363600
61 """
62 if not isinstance(number, int):
63 raise TypeError("Parameter number must be int")
64
65 if number < 0:
66 raise ValueError("Parameter number must be greater than or equal to 0")
67
68 # Converts number in string to iterate on its digits and adds its factorial.
69 return sum(DIGIT_FACTORIAL[digit] for digit in str(number))
70
71
72def solution(chain_length: int = 60, number_limit: int = 1000000) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected