Skip to content
Open
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
50 changes: 50 additions & 0 deletions other/krisnamurtyCheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Mengecek apakah krisnamurty atau bukan
from math import factorial


def krisnamurty(number : int) -> int | str:
"""
Angka Krisnamurty adalah angka factorial yang setiap digitnya
sama dengan factorial nya.
contoh :
145! = 1! + 4! + 5! -> Angka Krisnamurty
>>> krisnamurty(145)
'Angka Krisnamurty'
>>> krisnamurty(1)
'Angka Krisnamurty'
>>> krisnamurty(123)
'Bukan Angka Krisnamuty'
"""
error = "Masukkan Angka dengan benar"
benar , bukan = "Angka Krisnamurty" , "Bukan Angka Krisnamuty"
if number <= 0:
return error
else :
temp = number
total = 0
while temp > 0:
digit = temp % 10
total += factorial(digit)
temp //= 10
if total == number:
return benar
else :
return bukan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bisa pakai model list comprehension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jadi susah di pahamin nanti bang menurut ku



def main(args=None):
import doctest

doctest.testmod()

# sample case
print(krisnamurty(145)) # Angka Krisnamurty
print(krisnamurty(1)) # Angka Krisnamurty
print(krisnamurty(123)) # Bukan Angka Krisnamuty


if __name__ == "__main__":
main()
Loading