Program to get the factorial of the given number.

In this python basic program, we will get the factorial of the given number using while loop.

Steps to solve the program
  1. Take a number as input through the user and create a variable named fact and assign its value equal to 1.
  2. While the input number is greater than 0 multiply the fact by the number.
  3. After each multiplication subtract 1 from the input number.
  4. Print the output,
				
					num = n = int(input("Enter a number: "))
fact = 1
while n > 0:
    fact *= n
    n -= 1
print(f"Factorial of {num}: {fact}")
				
			

Output :

				
					Enter a number: 5
Factorial of 5: 120
				
			


Previous

calculate days between 2 dates.


Next

reverse a given number.

Leave a Comment