How to Find the Factorial of a Number using Python?

Factorial of a number is the product of all integers between 1 and itself. To find factorial of a given number, let us form a for loop over a range from 1 to itself. Remember that range() function excludes the stop value. Hence stop value should be one more than the input number. 

Each number in range is cumulatively multiplied in a variable f which is initialised to 1


num=int(input('enter a number'))
for i in range(1,num+1):
print ('factorial of', num, '=',f)


Sample run of above code −

enter a number5
factorial of 5 = 120