Program to calculate the factorial of a number

In this program, we will calculate the factorial of a number.

Steps to solve the program
  1. Take a number as input through the user.
  2. Create a variable and assign its value equal to 1.
  3. While the number is greater than 0 multiply the variable by given number and subtract 1 from the number.
  4. Print the output in the end.
				
					num=int(input("Enter a number: "))
fact = 1

while num>0:
    fact = fact*num
    num = num-1

print(f"factorial of {num} is: ",fact)
				
			

Output :

				
					Enter a number: 5
factorial of 5 is:  120
				
			

find all factors of a number

check whether a number is a Prime number or not

Leave a Comment