Get factorial of any number in Python
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 4 )
Input = int(input(“Enter number:”))
factorial=1
for i in range(1,Input+1):
factorial=factorial*i
factorial
def factorial(n):
if n==0 or n==1:
return 1
else:
ans=1
for i in range(1,n+1):
ans*=i
return ans
if __name__==’__main__’:
n=int(input(“Enter a number”))
print(“the factorial of the number is”,factorial(n))
def factorial(x):
y=[]
while x>1:
y.append(x)
x=x-1
product=np.product(y)
print(product)
factorial(4)
Output: 24
input = 6
fact=1
for i in range(1,input+1):
fact=fact*i
print(fact)