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

Function krishnamurthy

maths/special_numbers/krishnamurthy_number.py:26–41  ·  view source on GitHub ↗

>>> krishnamurthy(145) True >>> krishnamurthy(240) False >>> krishnamurthy(1) True

(number: int)

Source from the content-addressed store, hash-verified

24
25
26def krishnamurthy(number: int) -> bool:
27 """
28 >>> krishnamurthy(145)
29 True
30 >>> krishnamurthy(240)
31 False
32 >>> krishnamurthy(1)
33 True
34 """
35
36 fact_sum = 0
37 duplicate = number
38 while duplicate > 0:
39 duplicate, digit = divmod(duplicate, 10)
40 fact_sum += factorial(digit)
41 return fact_sum == number
42
43
44if __name__ == "__main__":

Callers 1

Calls 1

factorialFunction · 0.70

Tested by

no test coverage detected