Question about factoriel function!

Hello FCC campers, well i have question !!
As factorial of 1 equals 1, can we use factorial 1 as base condition instead of factorial 0 ?

initialise some variable with 1
lets say
fact = 1
then your code.

1 Like

Can you be more clear please xD i didn’t understand !!

num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print(“factorial can not be calclated”)
elif num == 0:
print(“The factorial of 0 is 1”)
else:
for i in range(1,num + 1):
factorial = factorial*i
print(“The factorial of”,num,“is”,factorial)

Hope this help!!

1 Like

Yes, you can certainly do that.

1 Like

Thank you it’s more clear !!!

Thank you for the answer !!

remember that
factorial(0) can be passed
if you use as base case num === 1 how do you deal when num is equal to 0?

never just use equality, there are “equal or less than” and “equal or more than” that will help prevent bugs

1 Like

i like the way you explain it, Thank you so much !!