Skip to content

Instantly share code, notes, and snippets.

@rbelando
Created January 26, 2020 19:00
Show Gist options
  • Save rbelando/cc1e6a2b88a0a4205bb6a6c8570384dc to your computer and use it in GitHub Desktop.
Save rbelando/cc1e6a2b88a0a4205bb6a6c8570384dc to your computer and use it in GitHub Desktop.
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