syntax to find factorial of a number

##### Title

##### Question

*Respected sir/mam, in the 2 question we got to know how to find the factorial of the numbers from 1 to 20 . could you please tell me how to find the factorial of a particular number say factorial of 10 i.e 10! ?*Python-3.4.3 Getting-started-with-for 09-10 min 50-60 sec

__Answers:__

def factorial(n):

fact = 1

if n < 0:

return "Factorial does not exists for negative numbers"

elif num == 0:

return 1

else:

for i in range(1, n + 1):

fact = fact * i

return fact

factorial(10)

num=int(input('enter a number'))

fact=1

for i in range(1,num+1):

fact=fact*i

print ('factorial of', num, '=',fact)

but how do i write a code for negative input values?...like factorial of negative indices does not exist

Login to add comment

15-03-21, 12:49 p.m.shraddhakb1893@gmail.com15-03-21, 7:33 p.m.shraddhakb1893@gmail.comLogin to add comment