Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added Python Program to Check Krishnamurthy Number
  • Loading branch information
Utsav1999 committed Jul 28, 2020
commit 1b73ff978c1ea9e48abb79a70516ab83b954b76e
9 changes: 5 additions & 4 deletions maths/krishnamurthy_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def factorial(digit: int) -> int:
return 1 if(digit == 0 or digit == 1) else (digit * factorial(digit - 1))
return 1 if (digit == 0 or digit == 1) else (digit * factorial(digit - 1))


def krishnamurthy(number: int) -> bool:
Expand All @@ -25,10 +25,9 @@ def krishnamurthy(number: int) -> bool:
>>> krishnamurthy(1)
"""


factSum = 0
duplicate = number
while(duplicate > 0):
while duplicate > 0:
factSum += factorial(duplicate % 10)
duplicate //= 10
return factSum == number
Expand All @@ -37,4 +36,6 @@ def krishnamurthy(number: int) -> bool:
if __name__ == "__main__":
print("Program to check whether a number is a Krisnamurthy Number or not")
number = int(input("Enter number: ").strip())
print(f"{number} is {'' if krishnamurthy(number) else 'not '} a Krishnamurthy Number.")
print(
f"{number} is {'' if krishnamurthy(number) else 'not '} a Krishnamurthy Number."
)