def fact_rec(n):
if n < 0:
return
elif n <= 1:
return 1
else:
return n*fact_rec(n-1)
answer = fact_rec(4)
if answer == None:
print("Cannot calculate factorial of a negative value")
else:
print(answer) # 24 = 4x3x2x1 = 4!
def factorial(n):
assert type(n) == int, "Invalid input type"
assert n >= 0, "Input must be non-negative"
if n <= 1:
return n
else:
return n*factorial(n-1)
def recursive_factorial(n: int) -> int:
if n<=1: return n
return n * factorial(n-1)