Created
January 26, 2020 19:00
-
-
Save rbelando/cc1e6a2b88a0a4205bb6a6c8570384dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(number: int): | |
if number == 0: | |
r = 1 | |
else: | |
r = number * factorial(number - 1) | |
return r | |
def is_factorial(number: int) -> bool: | |
result = False | |
operand_number = number | |
while operand_number >= 1: | |
fact_result = factorial(operand_number) | |
if number == fact_result: | |
result = True | |
break | |
else: | |
operand_number = operand_number - 1 | |
return result | |
print(is_factorial(3)) # False | |
print(is_factorial(6)) # True | |
print(is_factorial(0)) # False | |
print(is_factorial(1)) # True | |
print(is_factorial(24)) # True | |
print(is_factorial(120)) # True | |
print(is_factorial(125)) # False | |
print(is_factorial(720)) # True | |
print(is_factorial(-6)) # False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment